/[A3C]/lib/A3C/AAIEduHr.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/AAIEduHr.pm

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

revision 89 by dpavlin, Tue Apr 29 21:43:36 2008 UTC revision 93 by dpavlin, Wed Apr 30 17:23:21 2008 UTC
# Line 12  AAAIEduHr Line 12  AAAIEduHr
12  Pull varios stuff from XML at L<http://shema.aaiedu.hr/> and cache it as  Pull varios stuff from XML at L<http://shema.aaiedu.hr/> and cache it as
13  JSON on disk  JSON on disk
14    
15    =head1 METHODS
16    
17  =cut  =cut
18    
19  #use base 'Jifty::Object';  #use base 'Jifty::Object';
# Line 21  use Data::Dump qw/dump/; Line 23  use Data::Dump qw/dump/;
23  use File::Slurp;  use File::Slurp;
24  use JSON::XS;  use JSON::XS;
25    
26    =head2 vocabulary
27    
28      valid are A3C::AAIEduHr->vocabulary('hrEdu001'),
29    
30      valid are [ '', A3C::AAIEduHr->vocabulary('hrEdu001') ],
31    
32    =cut
33    
34  sub vocabulary {  sub vocabulary {
35          my $self = shift;          my $self = shift;
36    
# Line 53  sub vocabulary { Line 63  sub vocabulary {
63          my $data;          my $data;
64    
65          if ( ! -e $data_path ) {          if ( ! -e $data_path ) {
66                  my $rules = XML::Rules->new( rules => [                  my $rules = XML::Rules->new(
67                    stripspaces => 8,
68                    rules => [
69                          _default => sub {                          _default => sub {
70                                  my ($tag_name, $tag_hash, $context, $parent_data) = @_;                                  my ($tag_name, $tag_hash, $context, $parent_data) = @_;
71                                  warn "_default $tag_name ",dump( $tag_hash );                                  warn "_default $tag_name ",dump( $tag_hash );
# Line 62  sub vocabulary { Line 74  sub vocabulary {
74                          vocabulary => 'no content',                          vocabulary => 'no content',
75                          vocabularyentry => sub {                          vocabularyentry => sub {
76                                  die "no key attribute?" unless defined( $_[1]->{key} );                                  die "no key attribute?" unless defined( $_[1]->{key} );
77                                   '@' . $_[0] => $_[1]->{key};                                  my $v = {
78                                            display =>      $_[1]->{_content},
79                                            value   =>      $_[1]->{key},
80                                    };
81                                    # if same, just store key
82                                    $v = $_[1]->{key} if ( $v->{display} eq $v->{value} );
83                                    '@' . $_[0] => $v;
84                          },                          },
85                  ]);                  ]);
86                  $data = $rules->parsefile( $xml_path )                  $data = $rules->parsefile( $xml_path )
# Line 77  sub vocabulary { Line 95  sub vocabulary {
95                  Jifty->log->info("loaded dump from $data_path");                  Jifty->log->info("loaded dump from $data_path");
96          }          }
97    
98          warn '## ',ref($data),' = ',dump($data);  #       warn '## ',ref($data),' = ',dump($data);
99    
100          die "data not for for $name" unless $data->{name} eq $name;          die "data not for for $name" unless $data->{name} eq $name;
101          warn "no vocabularyentry for $name from $data_path" unless defined( $data->{vocabularyentry} );          warn "no vocabularyentry for $name from $data_path" unless defined( $data->{vocabularyentry} );
102    
103            return @{ $data->{vocabularyentry} } if wantarray;
104          return $data->{vocabularyentry};          return $data->{vocabularyentry};
105  }  }
106    

Legend:
Removed from v.89  
changed lines
  Added in v.93

  ViewVC Help
Powered by ViewVC 1.1.26