extract template parsing into _parse_template as a step towards isis_template
git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@1023
07558da8-63fa-0310-ba24-
9fe276d99e06
my $fields_re = join('|', keys %$to_subfields );
my $fields_re = join('|', keys %$to_subfields );
my $fill_in;
my @marc_out;
my $fill_in;
my @marc_out;
- my ( $marc_template_order, @marc_order ); # = _parse_template( $args->{marc_template} );
+ my $marc_template;
+ _parse_template( $args->{marc_template}, $marc_template );
- my $templates = $args->{marc_template};
+ sub _parse_template {
+ my ( $templates, $marc_template_order ) = @_;
- foreach my $template ( @{ $templates } ) {
- my $count;
- my @marc_order;
- sub my_count {
- my $sf = shift;
- my $nr = $count->{$sf}++;
- push @marc_order, [ $sf, $nr ];
- return $sf . $nr;
+ foreach my $template ( @{ $templates } ) {
+ our $count = {};
+ our @marc_order = ();
+ sub my_count {
+ my $sf = shift;
+ my $nr = $count->{$sf}++;
+ push @marc_order, [ $sf, $nr ];
+ return $sf . $nr;
+ }
+ my $pos_template = $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 ];
- my $pos_template = $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 ),$/;
- $pos_templates->{ $count_key } = $pos_template;
- $marc_template_order->{ $pos_template } = [ @marc_order ];
+ warn "### from ",dump( $templates ), " created ", dump( $marc_template );
- warn "### from ",dump( $templates ), " created ", dump( $pos_templates ), " and ", dump( $marc_template_order );
+
+ warn "### marc_template = ",dump( $marc_template );
warn "### from_count = ",dump( $from_count ), $/;
warn "### to_count = ",dump( $to_count ), $/;
warn "### from_count = ",dump( $from_count ), $/;
warn "### to_count = ",dump( $to_count ), $/;
- my $template = $pos_templates->{ $from_count_key } ||
- die "I don't have template for:\n$from_count_key\n## available templates\n", dump( $pos_templates );
+ 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} );
warn "### selected template: |$template|\n";
warn "### selected template: |$template|\n";
warn "#### >>>> $sf with fill_in = ",dump( $fill_in ),$/;
}
warn "#### >>>> $sf with fill_in = ",dump( $fill_in ),$/;
}
- warn "## template: |$template|\n## marc_template_order = ",dump( $marc_template_order );
+ warn "## template: |$template|\n## marc_template = ",dump( $marc_template );
- foreach my $sf ( @{ $marc_template_order->{$template} } ) {
+ foreach my $sf ( @{ $marc_template->{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";
my ( $sf, $nr ) = @$sf;
my $v = $fill_in->{$sf}->[$nr] || die "can't find fill_in $sf/$nr";
warn "++ $sf/$nr |$v|\n";