1 |
package WebPAC::Normalize; |
package WebPAC::Normalize; |
2 |
use Exporter 'import'; |
use Exporter 'import'; |
3 |
our @EXPORT = qw/ |
our @EXPORT = qw/ |
4 |
_set_rec _set_lookup |
_set_ds _set_lookup |
5 |
_set_load_row |
_set_load_row |
6 |
_get_ds _clean_ds |
_get_ds _clean_ds |
7 |
_debug |
_debug |
47 |
|
|
48 |
=cut |
=cut |
49 |
|
|
50 |
our $VERSION = '0.31'; |
our $VERSION = '0.32'; |
51 |
|
|
52 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
53 |
|
|
105 |
die "need row argument" unless ($arg->{row}); |
die "need row argument" unless ($arg->{row}); |
106 |
die "need normalisation argument" unless ($arg->{rules}); |
die "need normalisation argument" unless ($arg->{rules}); |
107 |
|
|
|
no strict 'subs'; |
|
108 |
_set_lookup( $arg->{lookup} ) if defined($arg->{lookup}); |
_set_lookup( $arg->{lookup} ) if defined($arg->{lookup}); |
109 |
_set_rec( $arg->{row} ); |
_set_ds( $arg->{row} ); |
110 |
_set_config( $arg->{config} ) if defined($arg->{config}); |
_set_config( $arg->{config} ) if defined($arg->{config}); |
111 |
_clean_ds( %{ $arg } ); |
_clean_ds( %{ $arg } ); |
112 |
$load_row_coderef = $arg->{load_row_coderef}; |
$load_row_coderef = $arg->{load_row_coderef}; |
113 |
|
|
114 |
eval "$arg->{rules}"; |
no strict 'subs'; |
115 |
|
no warnings 'redefine'; |
116 |
|
eval "$arg->{rules};"; |
117 |
die "error evaling $arg->{rules}: $@\n" if ($@); |
die "error evaling $arg->{rules}: $@\n" if ($@); |
118 |
|
|
119 |
return _get_ds(); |
return _get_ds(); |
120 |
} |
} |
121 |
|
|
122 |
=head2 _set_rec |
=head2 _set_ds |
123 |
|
|
124 |
Set current record hash |
Set current record hash |
125 |
|
|
126 |
_set_rec( $rec ); |
_set_ds( $rec ); |
127 |
|
|
128 |
=cut |
=cut |
129 |
|
|
130 |
my $rec; |
my $rec; |
131 |
|
|
132 |
sub _set_rec { |
sub _set_ds { |
133 |
$rec = shift or die "no record hash"; |
$rec = shift or die "no record hash"; |
134 |
} |
} |
135 |
|
|
1000 |
|
|
1001 |
=cut |
=cut |
1002 |
|
|
|
sub frec { |
|
|
my @out = rec(@_); |
|
|
warn "rec(",dump(@_),") has more than one return value, ignoring\n" if $#out > 0; |
|
|
return shift @out; |
|
|
} |
|
|
|
|
1003 |
sub rec { |
sub rec { |
1004 |
my @out; |
my @out; |
1005 |
if ($#_ == 0) { |
if ($#_ == 0) { |
1016 |
} |
} |
1017 |
} |
} |
1018 |
|
|
1019 |
|
=head2 frec |
1020 |
|
|
1021 |
|
Returns first value from field |
1022 |
|
|
1023 |
|
$v = frec('200'); |
1024 |
|
$v = frec('200','a'); |
1025 |
|
|
1026 |
|
=cut |
1027 |
|
|
1028 |
|
sub frec { |
1029 |
|
my @out = rec(@_); |
1030 |
|
warn "rec(",dump(@_),") has more than one return value, ignoring\n" if $#out > 0; |
1031 |
|
return shift @out; |
1032 |
|
} |
1033 |
|
|
1034 |
=head2 regex |
=head2 regex |
1035 |
|
|
1036 |
Apply regex to some or all values |
Apply regex to some or all values |