From 831a173ee3372529e4169be453b2bd332d8e712d Mon Sep 17 00:00:00 2001 From: djfiander Date: Wed, 20 May 2009 21:26:37 +0000 Subject: [PATCH] Refactor publication pattern parsing to make processing simpler later git-svn-id: svn://svn.open-ils.org/ILS/trunk@13212 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Utils/MFHD/Caption.pm | 40 ++++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm b/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm index 7ce488f3f9..3e4f5cf4f6 100755 --- a/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm +++ b/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm @@ -56,9 +56,9 @@ sub new # Calendar change can have multiple comma-separated values $self->{_mfhdc_PATTERN}->{x} = [split /,/, $val]; } elsif ($key eq 'y') { - $self->{_mfhdc_PATTERN}->{y} = [] + $self->{_mfhdc_PATTERN}->{y} = {} unless exists $self->{_mfhdc_PATTERN}->{y}; - push @{$self->{_mfhdc_PATTERN}->{y}}, $val; + update_pattern($self, $val); } elsif ($key eq 'o') { # Type of unit $self->{_mfhdc_UNIT} = $val; @@ -91,8 +91,8 @@ sub new # if the frequency is a number, then the pattern better # have that number of values associated with it. if (exists($pat->{w}) && ($pat->{w} =~ /^\d+$/) - && ($pat->{w} != scalar(@{$pat->{y}}))) { - carp("Caption::new: publication frequency '$pat->{w}' != publication pattern @{$pat->{y}}"); + && ($pat->{w} != scalar(@{$pat->{y}->{p}}))) { + carp("Caption::new: publication frequency '$pat->{w}' != publication pattern @{$pat->{y}->{p}}"); } @@ -103,13 +103,19 @@ sub new bless ($self, $class); - if (exists $pat->{y}) { - $self->decode_pattern; - } - return $self; } +sub update_pattern { + my $self = shift; + my $val = shift; + my $pathash = $self->{_mfhdc_PATTERN}->{y}; + my ($pubcode, $pat) = unpack("a1a*", $val); + + $pathash->{$pubcode} = [] unless exists $pathash->{$pubcode}; + push @{$pathash->{$pubcode}}, $pat; +} + sub decode_pattern { my $self = shift; my $pattern = $self->{_mfhdc_PATTERN}->{y}; @@ -378,13 +384,11 @@ sub regularity_match { my @date = @_; # we can't match something that doesn't exist. - return 0 if !exists $self->{_mfhdc_PATTERN}->{y}; - - foreach my $regularity (@{$self->{_mfhdc_PATTERN}->{y}}) { - next unless $regularity =~ m/^$pubcode/; + return 0 if !exists $self->{_mfhdc_PATTERN}->{y}->{$pubcode}; - my $chroncode= substr($regularity, 1, 1); - my @pats = split(/,/, substr($regularity, 2)); + foreach my $regularity (@{$self->{_mfhdc_PATTERN}->{y}->{$pubcode}}) { + my $chroncode= substr($regularity, 0, 1); + my @pats = split(/,/, substr($regularity, 1)); if (!exists $dispatch{$chroncode}) { carp "Unrecognized chroncode '$chroncode'"; @@ -430,12 +434,12 @@ sub enum_is_combined { my $iss = shift; my $level = ord($subfield) - ord('a') + 1; - return 0 if !exists $self->{_mfhdc_PATTERN}->{y}; + return 0 if !exists $self->{_mfhdc_PATTERN}->{y}->{c}; - foreach my $regularity (@{$self->{_mfhdc_PATTERN}->{y}}) { - next unless $regularity =~ m/^ce$level/o; + foreach my $regularity (@{$self->{_mfhdc_PATTERN}->{y}->{c}}) { + next unless $regularity =~ m/^e$level/o; - my @pats = split(/,/, substr($regularity, 3)); + my @pats = split(/,/, substr($regularity, 2)); foreach my $pat (@pats) { $pat =~ s|/.+||; # if it's a combined issue, match the start -- 2.11.0