80 |
|
|
81 |
my $fields_re = join('|', keys %$to_subfields ); |
my $fields_re = join('|', keys %$to_subfields ); |
82 |
|
|
|
my $pos_templates; |
|
83 |
my $fill_in; |
my $fill_in; |
84 |
my @marc_out; |
my @marc_out; |
85 |
|
|
86 |
my ( $marc_template_order, @marc_order ); # = _parse_template( $args->{marc_template} ); |
my $marc_template; |
87 |
|
_parse_template( $args->{marc_template}, $marc_template ); |
88 |
|
|
89 |
my $templates = $args->{marc_template}; |
sub _parse_template { |
90 |
|
my ( $templates, $marc_template_order ) = @_; |
91 |
|
|
92 |
foreach my $template ( @{ $templates } ) { |
foreach my $template ( @{ $templates } ) { |
93 |
my $count; |
our $count = {}; |
94 |
my @marc_order; |
our @marc_order = (); |
95 |
sub my_count { |
sub my_count { |
96 |
my $sf = shift; |
my $sf = shift; |
97 |
my $nr = $count->{$sf}++; |
my $nr = $count->{$sf}++; |
98 |
push @marc_order, [ $sf, $nr ]; |
push @marc_order, [ $sf, $nr ]; |
99 |
return $sf . $nr; |
return $sf . $nr; |
100 |
|
} |
101 |
|
my $pos_template = $template; |
102 |
|
$pos_template =~ s/($fields_re)/my_count($1)/ge; |
103 |
|
my $count_key = dump( $count ); |
104 |
|
warn "### template: |$template| -> |$pos_template| count = $count_key marc_order = ",dump( @marc_order ),$/; |
105 |
|
$marc_template->{pos}->{ $count_key } = $pos_template; |
106 |
|
$marc_template->{order}->{ $pos_template } = [ @marc_order ]; |
107 |
} |
} |
108 |
my $pos_template = $template; |
warn "### from ",dump( $templates ), " created ", dump( $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 ),$/; |
|
|
$pos_templates->{ $count_key } = $pos_template; |
|
|
$marc_template_order->{ $pos_template } = [ @marc_order ]; |
|
109 |
} |
} |
110 |
warn "### from ",dump( $templates ), " created ", dump( $pos_templates ), " and ", dump( $marc_template_order ); |
|
111 |
|
warn "### marc_template = ",dump( $marc_template ); |
112 |
|
|
113 |
my $m; |
my $m; |
114 |
|
|
141 |
warn "### from_count = ",dump( $from_count ), $/; |
warn "### from_count = ",dump( $from_count ), $/; |
142 |
warn "### to_count = ",dump( $to_count ), $/; |
warn "### to_count = ",dump( $to_count ), $/; |
143 |
|
|
144 |
my $template = $pos_templates->{ $from_count_key } || |
my $template = $marc_template->{pos}->{ $from_count_key } || |
145 |
die "I don't have template for:\n$from_count_key\n## available templates\n", dump( $pos_templates ); |
die "I don't have template for:\n$from_count_key\n## available templates\n", dump( $marc_template->{pos} ); |
146 |
|
|
147 |
warn "### selected template: |$template|\n"; |
warn "### selected template: |$template|\n"; |
148 |
|
|
172 |
warn "#### >>>> $sf with fill_in = ",dump( $fill_in ),$/; |
warn "#### >>>> $sf with fill_in = ",dump( $fill_in ),$/; |
173 |
} |
} |
174 |
|
|
175 |
warn "## template: |$template|\n## marc_template_order = ",dump( $marc_template_order ); |
warn "## template: |$template|\n## marc_template = ",dump( $marc_template ); |
176 |
|
|
177 |
foreach my $sf ( @{ $marc_template_order->{$template} } ) { |
foreach my $sf ( @{ $marc_template->{order}->{$template} } ) { |
178 |
my ( $sf, $nr ) = @$sf; |
my ( $sf, $nr ) = @$sf; |
179 |
my $v = $fill_in->{$sf}->[$nr] || die "can't find fill_in $sf/$nr"; |
my $v = $fill_in->{$sf}->[$nr] || die "can't find fill_in $sf/$nr"; |
180 |
warn "++ $sf/$nr |$v|\n"; |
warn "++ $sf/$nr |$v|\n"; |