--- trunk/lib/WebPAC/Normalize.pm 2006/06/26 16:39:51 536 +++ trunk/lib/WebPAC/Normalize.pm 2006/06/29 15:29:19 538 @@ -1,8 +1,9 @@ package WebPAC::Normalize; use Exporter 'import'; @EXPORT = qw/ - set_rec set_lookup - get_ds clean_ds + _set_rec _set_lookup + _get_ds _clean_ds + tag search display rec1 rec2 rec regex prefix suffix surround @@ -21,11 +22,11 @@ =head1 VERSION -Version 0.04 +Version 0.05 =cut -our $VERSION = '0.04'; +our $VERSION = '0.05'; =head1 SYNOPSIS @@ -42,11 +43,14 @@ =head1 FUNCTIONS +Functions which start with C<_> are private and used by WebPAC internally. +All other functions are available for use within normalisation rules. + =head2 data_structure Return data structure - my $ds = WebPAC::Normalize( + my $ds = WebPAC::Normalize::data_structure( lookup => $lookup->lookup_hash, row => $row, rules => $normalize_pl_config, @@ -54,6 +58,9 @@ This function will B if normalizastion can't be evaled. +Since this function isn't exported you have to call it with +C. + =cut sub data_structure { @@ -63,28 +70,68 @@ die "need normalisation argument" unless ($arg->{rules}); no strict 'subs'; - set_lookup( $arg->{lookup} ); - set_rec( $arg->{row} ); - clean_ds(); + _set_lookup( $arg->{lookup} ); + _set_rec( $arg->{row} ); + _clean_ds(); eval "$arg->{rules}"; die "error evaling $arg->{rules}: $@\n" if ($@); - return get_ds(); + return _get_ds(); } -=head2 set_rec +=head2 _set_rec Set current record hash - set_rec( $rec ); + _set_rec( $rec ); =cut my $rec; -sub set_rec { +sub _set_rec { $rec = shift or die "no record hash"; } +=head2 _get_ds + +Return hash formatted as data structure + + my $ds = _get_ds(); + +=cut + +my $out; + +sub _get_ds { + return $out; +} + +=head2 _clean_ds + +Clean data structure hash for next record + + _clean_ds(); + +=cut + +sub _clean_ds { + $out = undef; +} + +=head2 _set_lookup + +Set current lookup hash + + _set_lookup( $lookup ); + +=cut + +my $lookup; + +sub _set_lookup { + $lookup = shift; +} + =head2 tag Define new tag for I and I. @@ -94,8 +141,6 @@ =cut -my $out; - sub tag { my $name = shift or die "tag needs name as first argument"; my @o = grep { defined($_) && $_ ne '' } @_; @@ -137,44 +182,6 @@ $out->{$name}->{search} = \@o; } -=head2 get_ds - -Return hash formatted as data structure - - my $ds = get_ds(); - -=cut - -sub get_ds { - return $out; -} - -=head2 clean_ds - -Clean data structure hash for next record - - clean_ds(); - -=cut - -sub clean_ds { - $out = undef; -} - -=head2 set_lookup - -Set current lookup hash - - set_lookup( $lookup ); - -=cut - -my $lookup; - -sub set_lookup { - $lookup = shift; -} - =head2 rec1 Return all values in some field