root/branches/boomer/extlib/TheSchwartz/FuncMap.pm @ 1098

Revision 1098, 1.0 kB (checked in by hachi, 2 years ago)

Branching for boomer from release-19, rev 62318

  • Property svn:keywords set to Id Revision
Line 
1# $Id$
2
3package TheSchwartz::FuncMap;
4use strict;
5use base qw( Data::ObjectDriver::BaseObject );
6
7use Carp qw( croak );
8
9__PACKAGE__->install_properties({
10               columns     => [ qw( funcid funcname ) ],
11               datasource  => 'funcmap',
12               primary_key => 'funcid',
13           });
14
15sub create_or_find {
16    my $class = shift;
17    my($driver, $funcname) = @_;
18
19    ## Attempt to insert a new funcmap row. Since the funcname column is
20    ## UNIQUE, if the row already exists, an exception will be thrown.
21    my $map = $class->new;
22    $map->funcname($funcname);
23    eval { $driver->insert($map) };
24
25    ## If we got an exception, try to load the record with this funcname;
26    ## in all likelihood, the exception was that the record was added by
27    ## another process.
28    if (my $err = $@) {
29        ($map) = $driver->search('TheSchwartz::FuncMap' =>
30                { funcname => $funcname }
31            ) or croak "Can't find or create funcname $funcname: $err";
32    }
33    return $map;
34}
35
361;
Note: See TracBrowser for help on using the browser.