<body>
<table>
[%
- FOREACH d IN data ;
+ FOREACH key IN data.keys ;
+ d = data.key ;
IF d.display
-%]
<tr class="[% d.tag %]">
Retrive from disk one data_structure records using field 000 as key
- my @ds = $db->load_ds($rec);
+ my $ds = $db->load_ds($rec);
This function will also perform basic sanity checking on returned
data and disable caching if data is corrupted (or changed since last
update).
-Returns array or undef if cacheing is disabled or unavailable.
+Returns hash or undef if cacheing is disabled or unavailable.
=cut
}
};
if ($ok && $ds_ref->{'ds'}) {
- return @{ $ds_ref->{'ds'} };
+ return $ds_ref->{'ds'};
} else {
$log->warn("cache entry $cache_path corrupt. Use rm $cache_path/* to re-create it on next run!");
undef $self->{'path'};
Store data_structure on disk.
$db->save_ds(
- ds => \@ds,
+ ds => $ds,
current_filename => $self->{'current_filename'},
headline => $self->{'headline'},
);
=head1 VERSION
-Version 0.01
+Version 0.02
=cut
-our $VERSION = '0.01';
+our $VERSION = '0.02';
=head1 SYNOPSIS
This structures are used to produce output.
- my @ds = $webpac->data_structure($rec);
+ my $ds = $webpac->data_structure($rec);
B<Note: historical oddity follows>
my $cache_file;
if ($self->{'db'}) {
- my @ds = $self->{'db'}->load_ds($rec);
- $log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper(@ds) });
- return @ds if ($#ds > 0);
+ my $ds = $self->{'db'}->load_ds($rec);
+ $log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper($ds) });
+ return $ds if ($ds);
$log->debug("cache miss, creating");
}
$self->{tags_by_order} = \@sorted_tags;
}
- my @ds;
+ my $ds;
$log->debug("tags: ",sub { join(", ",@sorted_tags) });
# TODO: name_sigular, name_plural
my $name = $self->{'import_xml'}->{'indexer'}->{$field}->{'name'};
- $row->{'name'} = $name ? $self->_x($name) : $field;
+ my $row_name = $name ? $self->_x($name) : $field;
# post-sort all values in field
if ($self->{'import_xml'}->{'indexer'}->{$field}->{'sort'}) {
$log->warn("sort at field tag not implemented");
}
- push @ds, $row;
+ $ds->{$row_name} = $row;
$log->debug("row $field: ",sub { Dumper($row) });
}
$log->logdie("there is no current_filename defined! Do you have filename tag in conf/normalize/?.xml") unless ($self->{'current_filename'});
$self->{'db'}->save_ds(
- ds => \@ds,
+ ds => $ds,
current_filename => $self->{'current_filename'},
headline => $self->{'headline'},
) if ($self->{'db'});
- $log->debug("ds: ", sub { Dumper(@ds) });
+ $log->debug("ds: ", sub { Dumper($ds) });
- return @ds;
+ $log->logconfess("data structure returned is not array any more!") if wantarray;
+
+ return $ds;
}
my $text = $tt->apply(
template => 'text.tt',
- data => \@ds
+ data => $ds
);
It also has follwing template toolikit filter routies defined:
=head3 tt_filter_type
-filter to return values of specified from @ds
+filter to return values of specified from $ds
=cut
my ($name,$join) = @_;
- die "no data array" unless ($data->{'data'} && ref($data->{'data'}) eq 'ARRAY');
+ die "no data hash" unless ($data->{'data'} && ref($data->{'data'}) eq 'HASH');
# Hm? Should we die here?
return unless ($name);
- my $item = first { $_->{'name'} eq $name } @{ $data->{'data'} };
-
- return unless($item);
+ my $item = $data->{'data'}->{$name} || return;
my $v = $item->{$type} || return;
$tt->to_file(
file => 'out.txt',
template => 'text.tt',
- data => \@ds
+ data => $ds
);
=cut
ok(! $found, "not found");
}
-ok(my @ds = $n->data_structure( $rec ), "data_structure");
+ok(my $ds = $n->data_structure( $rec ), "data_structure");
+
+diag Dumper($rec, $ds);
-#diag Dumper($rec, \@ds);
ok(! $db->path(''), "path - disable caching");
-cmp_ok($db->{'path'}, '==', undef, "no path");
+ok(! defined($db->{'path'}), "no path");
ok($db->path( $path ), "path($path)");
ok(! $db->save_ds(), "save_ds");
-my @ds = [ {
- 'name' => 'Izvor: ',
- 'tag' => 'Source',
- 'display' => [ 'foo' ]
- }, {
- 'name' => 'ID',
- 'tag' => 'IDths',
- 'swish' => [ 'bar' ],
- 'lookup_key' => [ 'bar' ]
- }, {
+my $ds = {
+ 'Source' => {
+ 'name' => 'Izvor: ',
+ 'tag' => 'Source',
+ 'display' => [ 'foo' ]
+ },
+ 'ID' => {
+ 'name' => 'ID',
+ 'tag' => 'IDths',
+ 'swish' => [ 'bar' ],
+ 'lookup_key' => [ 'bar' ]
+ },
'filename' => [ 'out/thes/001.html' ],
'name' => 'filename',
'tag' => 'filename'
- },
-];
+};
ok(! $db->save_ds(), "empty save_ds");
throws_ok { $db->save_ds( foo => 1 ) } qr/ds/, "save_ds - ds";
-throws_ok { $db->save_ds( ds => \@ds ) } qr/current_filename/, "save_ds - current_filename";
-throws_ok { $db->save_ds( ds => \@ds, 'current_filename' => 'foo' ) } qr/headline/, "save_ds - headline";
+throws_ok { $db->save_ds( ds => $ds ) } qr/current_filename/, "save_ds - current_filename";
+throws_ok { $db->save_ds( ds => $ds, 'current_filename' => 'foo' ) } qr/headline/, "save_ds - headline";
-ok($db->save_ds( ds => \@ds, 'current_filename' => 'foo', 'headline' => 'bar' ), "save_ds");
+ok($db->save_ds( ds => $ds, 'current_filename' => 'foo', 'headline' => 'bar' ), "save_ds");
-ok(my @ds2 = $db->load_ds({ '000' => '000' }), "load_ds");
+ok(my $ds2 = $db->load_ds({ '000' => '000' }), "load_ds");
-is_deeply(\@ds, \@ds2, "loaded data");
+is_deeply($ds, $ds2, "loaded data");
ok(! $db->load_ds({ '000' => 42 }), "load_ds non-existing");
no_log => 1,
), "new");
-my @ds = [ {
- 'name' => 'Izvor: ',
- 'tag' => 'Source',
- 'display' => [ 'foo' ]
- }, {
- 'name' => 'ID',
- 'tag' => 'IDths',
- 'swish' => [ 'bar' ],
- 'lookup_key' => [ 'bar' ]
- }, {
+my $ds = {
+ 'Source' => {
+ 'name' => 'Izvor: ',
+ 'tag' => 'Source',
+ 'display' => [ 'foo' ]
+ },
+ 'ID' => {
+ 'name' => 'ID',
+ 'tag' => 'IDths',
+ 'swish' => [ 'bar' ],
+ 'lookup_key' => [ 'bar' ]
+ },
'filename' => [ 'out/thes/001.html' ],
'name' => 'filename',
'tag' => 'filename'
- },
-];
+};
throws_ok { $tt->apply( template => 'foo', data => [] ) } qr/error.*foo/, "apply without template";
-cmp_ok(my $text = $tt->apply( template => 'text.tt', data => @ds ), '=~', qr/Source.*foo/, "apply");
+cmp_ok(my $text = $tt->apply( template => 'text.tt', data => $ds ), '=~', qr/Source.*foo/, "apply");
diag $text;
while (my $row = $isis->fetch) {
- ok(my @ds = $n->data_structure($row), "data_structure");
+ ok(my $ds = $n->data_structure($row), "data_structure");
-# diag Dumper(\@ds);
+# diag Dumper($ds);
ok(my $html = $out->apply(
template => 'html.tt',
- data => \@ds,
+ data => $ds,
), "apply");
$html =~ s#\s*[\n\r]+\s*##gs;
if ($q->path_info =~ m#xml#) {
- my @ds = $db->load_ds($rec);
+ my $ds = $db->load_ds($rec);
- if (@ds && $#ds > 0) {
+ if ($ds) {
print qq{<response>
<action type='html' target='div_record' errorCode='' errorMessage='' >
}, $iconv_utf8->convert( $out->apply(
template => $template_file,
- data => \@ds,
+ data => $ds,
) ), qq{
</action>