/[A3C]/lib/A3C/Record.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/A3C/Record.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 54 by dpavlin, Tue Apr 1 19:27:06 2008 UTC revision 208 by dpavlin, Thu Jun 19 21:24:26 2008 UTC
# Line 5  use warnings; Line 5  use warnings;
5    
6  use base 'Jifty::Record';  use base 'Jifty::Record';
7    
8    use Data::Dump qw/dump/;
9    
10  =head1 NAME  =head1 NAME
11    
12  Custom Record class for A3C  Custom Record class for A3C
# Line 13  Custom Record class for A3C Line 15  Custom Record class for A3C
15    
16  =head2 load_or_create  =head2 load_or_create
17    
18  Perform canonicalization on C<load_or_create>  Perform canonicalization on C<load_or_create> and loads subset of columns
19    (which hopfully are indexes in model for performance reasons).
20    
21  =cut  =cut
22    
# Line 24  sub load_or_create { Line 27  sub load_or_create {
27                  ( $self, $class ) = ( $class, undef );                  ( $self, $class ) = ( $class, undef );
28          } else {          } else {
29                  $self = $class->new();                  $self = $class->new();
30      }          }
31    
32          my %args = (@_);          my %args = (@_);
33    
# Line 35  sub load_or_create { Line 38  sub load_or_create {
38                  );                  );
39          }          }
40    
41          my ( $id, $msg ) = $self->load_by_cols(%args);          my %load_cols;
42    
43            if ( ref($self) eq Jifty->app_class('Model','Person') ) {
44    
45                    $load_cols{$_} = $args{$_} foreach ( qw/
46                            uid
47                            hrEduPersonUniqueID
48                            mail
49                    / );
50            
51            } else {
52                    %load_cols = %args;
53            }
54    
55            my ( $id, $msg ) = $self->load_by_cols(%load_cols);
56          unless ( $self->id ) {          unless ( $self->id ) {
57                  return $self->create(%args);                  return $self->create(%args);
58          }          }
# Line 43  sub load_or_create { Line 60  sub load_or_create {
60          return ( $id, $msg );          return ( $id, $msg );
61  }  }
62    
63    =head2 create
64    
65    Serialize ARRAY values into single scalar separated by magic C<< <*> >> marker
66    
67    =cut
68    
69    sub create {
70            #warn "# create",dump(@_);
71            my $self = shift;
72            my %data = @_ or die "no data?";
73            foreach my $col ( keys %data ) {
74                    #warn "## ref($col)=",ref($col);
75                    $data{$col} = join(' <*> ', @{$data{$col}}) if ref( $data{$col} ) eq 'ARRAY';
76            }
77            #warn "## data = ",dump( %data );
78            $self->SUPER::create( %data );
79    }
80    
81    
82  1;  1;

Legend:
Removed from v.54  
changed lines
  Added in v.208

  ViewVC Help
Powered by ViewVC 1.1.26