--- trunk/lib/WebPAC/Input.pm 2006/05/14 12:34:50 487 +++ trunk/lib/WebPAC/Input.pm 2006/05/15 09:59:05 506 @@ -14,11 +14,11 @@ =head1 VERSION -Version 0.04 +Version 0.05 =cut -our $VERSION = '0.04'; +our $VERSION = '0.05'; =head1 SYNOPSIS @@ -160,6 +160,7 @@ limit => 500, offset => 6000, lookup => $lookup_obj, + stats => 1, ); By default, C is assumed to be C<852>. @@ -168,6 +169,8 @@ C is optional parametar to read just C records from database +C create optional report about usage of fields and subfields + Returns size of database, regardless of C and C parametars, see also C. @@ -224,7 +227,7 @@ filter => $filter_ref, ); - unless ($db) { + unless (defined($db)) { $log->logwarn("can't open database $arg->{path}, skipping..."); return; } @@ -253,7 +256,7 @@ # store size for later $self->{size} = ($to_rec - $from_rec) ? ($to_rec - $from_rec + 1) : 0; - $log->info("processing $self->{size}/$size records [$from_rec-$to_rec] convert $code_page -> $self->{code_page}"); + $log->info("processing $self->{size}/$size records [$from_rec-$to_rec] convert $code_page -> $self->{code_page}", $self->{stats} ? ' [stats]' : ''); # read database for (my $pos = $from_rec; $pos <= $to_rec; $pos++) { @@ -279,6 +282,25 @@ # create lookup $self->{'lookup'}->add( $rec ) if ($rec && $self->{'lookup'}); + # update counters for statistics + if ($self->{stats}) { + map { + my $fld = $_; + $self->{_stats}->{fld}->{ $fld }++; + if (ref($rec->{ $fld }) eq 'ARRAY') { + map { + if (ref($_) eq 'HASH') { + map { + $self->{_stats}->{sf}->{ $fld }->{ $_ }++; + } keys %{ $_ }; + } else { + $self->{_stats}->{repeatable}->{ $fld }++; + } + } @{ $rec->{$fld} }; + } + } keys %{ $rec }; + } + $self->progress_bar($pos,$to_rec) unless ($self->{no_progress_bar}); } @@ -400,6 +422,18 @@ return $self->{pos} = (($pos - 1) || -1); } +=head2 stats + +Dump statistics about field and subfield usage + + print Dumper( $input->stats ); + +=cut + +sub stats { + my $self = shift; + return $self->{_stats}; +} =head1 MEMORY USAGE