File Coverage

blib/lib/TheSchwartz/FuncMap.pm
Criterion Covered Total %
statement 9 20 45.0
branch 0 6 0.0
condition n/a
subroutine 3 4 75.0
pod 0 1 0.0
total 12 31 38.7


line stmt bran cond sub pod time code
1             # $Id$
2              
3             package TheSchwartz::FuncMap;
4 24     24   178 use strict;
  24         52  
  24         895  
5 24     24   133 use base qw( Data::ObjectDriver::BaseObject );
  24         47  
  24         15168  
6              
7 24     24   304744 use Carp qw( croak );
  24         67  
  24         4447  
8              
9             __PACKAGE__->install_properties(
10             { columns => [qw( funcid funcname )],
11             datasource => 'funcmap',
12             primary_key => 'funcid',
13             }
14             );
15              
16             sub create_or_find {
17 0     0 0   my $class = shift;
18 0           my ( $driver, $funcname ) = @_;
19              
20             ## Attempt to select funcmap record by name. If successful, return
21             ## object, otherwise proceed with insertion and return.
22 0           my ($map)
23             = $driver->search(
24             'TheSchwartz::FuncMap' => { funcname => $funcname } );
25 0 0         return $map if $map;
26              
27             ## Attempt to insert a new funcmap row. Since the funcname column is
28             ## UNIQUE, if the row already exists, an exception will be thrown.
29 0           $map = $class->new;
30 0           $map->funcname($funcname);
31 0           eval { $driver->insert($map) };
  0            
32              
33             ## If we got an exception, try to load the record with this funcname;
34             ## in all likelihood, the exception was that the record was added by
35             ## another process.
36 0 0         if ( my $err = $@ ) {
37 0 0         ($map)
38             = $driver->search(
39             'TheSchwartz::FuncMap' => { funcname => $funcname } )
40             or croak "Can't find or create funcname $funcname: $err";
41             }
42 0           return $map;
43             }
44              
45             1;