r1227@llin: dpavlin | 2007-05-24 10:26:01 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 24 May 2007 10:53:48 +0000 (10:53 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 24 May 2007 10:53:48 +0000 (10:53 +0000)
 generate humanly readable report or machine readable

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@834 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Validate.pm
run.pl
t/1-validate-delimiters.t

index f356046..32d55f0 100644 (file)
@@ -407,27 +407,48 @@ sub report {
 
 =head2 delimiters_templates
 
+Generate report of delimiter tamplates 
+
+  my $report = $validate->delimiter_teplates(
+       report => 1,
+  );
+
+Options:
+
+=over 4
+
+=item report
+
+Generate humanly readable report with single fields
+
+=back
 
 =cut
 
 sub delimiters_templates {
        my $self = shift;
 
+       my $args = {@_};
+
        my $t = $self->{_delimiters_templates};
 
        my $log = $self->_get_logger;
 
        unless ($t) {
-               $log->warn("called without delimiters");
+               $log->error("called without delimiters");
                return;
        }
 
        my $out;
 
        foreach my $f (sort { $a <=> $b } keys %$t) {
-               $out .= "$f\n";
-               foreach my $sft (sort { $a cmp $b } keys %{ $t->{$f} }) {
-                       $out .= "\t" . $t->{$f}->{$sft} . "\t$sft\n";
+               $out .= "$f\n" if ( $args->{report} );
+               foreach my $template (sort { $a cmp $b } keys %{ $t->{$f} }) {
+                       my $count = $t->{$f}->{$template};
+                       $out .= 
+                               ( $count ? "" : "# " ) .
+                               ( $args->{report} ? "" : "$f\t" ) .
+                               "\t$count\t$template\n";
                }
        }
 
diff --git a/run.pl b/run.pl
index f653aff..21fb841 100755 (executable)
--- a/run.pl
+++ b/run.pl
@@ -562,7 +562,7 @@ while (my ($database, $db_config) = each %{ $config->databases }) {
                                print $report_fh "$errors\n" if ($report_fh);
                        }
 
-                       print $report_fh "\nAll possible subfields/delimiter templates:\n", $validate->delimiters_templates, "\n\n";
+                       print $report_fh "\nAll possible subfields/delimiter templates:\n", $validate->delimiters_templates( report => 1 ), "\n\n";
                }
 
                if ($stats) {
index 8006037..d9a859c 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 5;
+use Test::More tests => 6;
 use Test::Exception;
 use blib;
 
@@ -66,3 +66,6 @@ is_deeply( $v->{_delimiters_templates}, {
 
 ok(my $dt = $v->delimiters_templates, 'delimiters_template');
 diag $dt;
+
+ok($dt = $v->delimiters_templates( report => 1 ), 'delimiters_template report');
+diag $dt;