1 |
dpavlin |
54 |
package A3C::Record; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
|
|
use base 'Jifty::Record'; |
7 |
|
|
|
8 |
|
|
=head1 NAME |
9 |
|
|
|
10 |
|
|
Custom Record class for A3C |
11 |
|
|
|
12 |
|
|
=head1 METHODS |
13 |
|
|
|
14 |
|
|
=head2 load_or_create |
15 |
|
|
|
16 |
|
|
Perform canonicalization on C<load_or_create> |
17 |
|
|
|
18 |
|
|
=cut |
19 |
|
|
|
20 |
|
|
sub load_or_create { |
21 |
|
|
my $class = shift; |
22 |
|
|
my $self; |
23 |
|
|
if ( ref($class) ) { |
24 |
|
|
( $self, $class ) = ( $class, undef ); |
25 |
|
|
} else { |
26 |
|
|
$self = $class->new(); |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
my %args = (@_); |
30 |
|
|
|
31 |
|
|
foreach my $key ( keys %args ) { |
32 |
|
|
$args{$key} = $self->run_canonicalization_for_column( |
33 |
|
|
column => $key, |
34 |
|
|
value => $args{$key} |
35 |
|
|
); |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
my ( $id, $msg ) = $self->load_by_cols(%args); |
39 |
|
|
unless ( $self->id ) { |
40 |
|
|
return $self->create(%args); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
return ( $id, $msg ); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
1; |