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 |
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 |
|
|
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 |
|
|
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 |
} |
} |
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; |