/[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

Contents of /lib/A3C/Record.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 208 - (show annotations)
Thu Jun 19 21:24:26 2008 UTC (15 years, 10 months ago) by dpavlin
File size: 1405 byte(s)
another round of re-factoring

- re-organize LDAP-related pages under /ldap with new view A3C::View::LDAP
- move record multi-value support into A3C::Record
- document multi-value solution which started it all
1 package A3C::Record;
2
3 use strict;
4 use warnings;
5
6 use base 'Jifty::Record';
7
8 use Data::Dump qw/dump/;
9
10 =head1 NAME
11
12 Custom Record class for A3C
13
14 =head1 METHODS
15
16 =head2 load_or_create
17
18 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
22
23 sub load_or_create {
24 my $class = shift;
25 my $self;
26 if ( ref($class) ) {
27 ( $self, $class ) = ( $class, undef );
28 } else {
29 $self = $class->new();
30 }
31
32 my %args = (@_);
33
34 foreach my $key ( keys %args ) {
35 $args{$key} = $self->run_canonicalization_for_column(
36 column => $key,
37 value => $args{$key}
38 );
39 }
40
41 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 ) {
57 return $self->create(%args);
58 }
59
60 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;

  ViewVC Help
Powered by ViewVC 1.1.26