r1586@llin: dpavlin | 2007-11-10 12:37:44 +0100
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 10 Nov 2007 11:37:47 +0000 (11:37 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 10 Nov 2007 11:37:47 +0000 (11:37 +0000)
 more re-factoring to support isis_template

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

lib/WebPAC/Normalize/MARC.pm

index ea61733..6aa45ed 100644 (file)
@@ -80,14 +80,12 @@ sub marc_template {
 
        my $fields_re = join('|', keys %$to_subfields );
 
-       my $fill_in;
        my @marc_out;
-
-       my $marc_template;
-       _parse_template( $args->{marc_template}, $marc_template );
+       
+       our $_template;
 
        sub _parse_template {
-               my ( $templates, $marc_template_order ) = @_;
+               my ( $name, $templates ) = @_;
 
                foreach my $template ( @{ $templates } ) {
                        our $count = {};
@@ -102,13 +100,15 @@ sub marc_template {
                        $pos_template =~ s/($fields_re)/my_count($1)/ge;
                        my $count_key = dump( $count );
                        warn "### template: |$template| -> |$pos_template| count = $count_key marc_order = ",dump( @marc_order ),$/;
-                       $marc_template->{pos}->{ $count_key } = $pos_template;
-                       $marc_template->{order}->{ $pos_template } = [ @marc_order ];
+                       $_template->{$name}->{pos}->{ $count_key } = $pos_template;
+                       $_template->{$name}->{order}->{ $pos_template } = [ @marc_order ];
                }
-               warn "### from ",dump( $templates ), " created ", dump( $marc_template );
+               warn "### from ",dump( $templates ), " created ", dump( $_template );
        }
 
-       warn "### marc_template = ",dump( $marc_template );
+       _parse_template( 'marc', $args->{marc_template} );
+       _parse_template( 'isis', $args->{isis_template} );
+       warn "### _template = ",dump( $_template );
 
        my $m;
 
@@ -141,12 +141,12 @@ sub marc_template {
                warn "### from_count = ",dump( $from_count ), $/;
                warn "### to_count   = ",dump( $to_count ), $/;
 
-               my $template = $marc_template->{pos}->{ $from_count_key } ||
-                       die "I don't have template for:\n$from_count_key\n## available templates\n", dump( $marc_template->{pos} );
+               my $template = $_template->{marc}->{pos}->{ $from_count_key } ||
+                       die "I don't have template for:\n$from_count_key\n## available templates\n", dump( $_template );
 
                warn "### selected template: |$template|\n";
 
-               $fill_in = {};
+               our $fill_in = {};
 
                my @templates = split(/\|/, $template );
                @templates = ( $template );
@@ -172,9 +172,9 @@ sub marc_template {
                        warn "#### >>>> $sf with fill_in = ",dump( $fill_in ),$/;
                }
 
-               warn "## template: |$template|\n## marc_template = ",dump( $marc_template );
+               warn "## template: |$template|\n## _template->marc = ",dump( $_template->{marc} );
 
-               foreach my $sf ( @{ $marc_template->{order}->{$template} } ) {
+               foreach my $sf ( @{ $_template->{marc}->{order}->{$template} } ) {
                        my ( $sf, $nr ) = @$sf;
                        my $v = $fill_in->{$sf}->[$nr] || die "can't find fill_in $sf/$nr";
                        warn "++ $sf/$nr |$v|\n";