1 package Equinox::Migration::MapDrivenXMLProc;
7 use Equinox::Migration::SubfieldMapper;
11 Equinox::Migration::MapDrivenXMLProc
19 our $VERSION = '1.000';
26 use Equinox::Migration::MapDrivenXMLProc;
41 my ($class, %args) = @_;
43 my $self = bless { conf => { count => 0,
47 map => Equinox::Migration::SubfieldMapper->new(file => $args{mapfile}),
49 twig => XML::Twig->new( twig_handlers => { record => \&record } ),
52 if ($args{marcfile}) {
53 if (-r $args{marcfile}) {
54 $self->{conf}{marc} = $args{marcfile};
57 die "Can't open marc file: $!\n";
60 $self->{twig}->parsefile($self->{conf}{marc});
73 my $c = $self->{conf};
74 return if $c->{quiet};
76 my $percent = int(($c->{count} / $c->{total}) * 100);
77 print STDERR "\r$percent% done (", $c->{count}, ")";
81 =head2 XML::Twig CALLBACK ROUTINES
89 $self->{holdings} = {};
91 my @dfields = $r->children('datafield');
92 for my $d (@dfields) {
93 process_datafields($d);
99 =head3 process_datafields
103 sub process_datafields {
105 my $map = $self->{map};
106 my $tag = $d->{'att'}->{'tag'};
109 my $s = $d->first_child('subfield');
110 $self->{holdings}{id} = $s->text;;
111 } elsif ($map->has($tag)) {
112 push @{$self->{holdings}{copies}}, { tag => $tag };
113 my @subs = $d->children('subfield');
115 { process_subs($tag, $sub) }
124 my ($tag, $sub) = @_;
125 my $map = $self->{map};
126 my $code = $sub->{'att'}->{'code'};
128 unless ($map->has($tag, $code)) {
129 # this is a subfield code we don't have mapped. report on it if this is a sample tag
130 push @{$c->{sample}{$tag}}, $code if defined $c->{sample}{tag};
134 my $copy = $self->{holdings}{copies}[-1];
135 my $field = $map->field($tag, $code);
136 if ($map->mod($field) eq 'multi') {
137 my $name = $tag . $code;
138 push @{$copy->{multi}{$name}}, $sub->text;
140 $copy->{uni}{$code} = $sub->text;
146 Shawn Boyette, C<< <sboyette at esilibrary.com> >>
150 Please report any bugs or feature requests to the above email address.
154 You can find documentation for this module with the perldoc command.
156 perldoc Equinox::Migration::MapDrivenXMLProc
159 =head1 COPYRIGHT & LICENSE
161 Copyright 2009 Equinox, all rights reserved.
163 This program is free software; you can redistribute it and/or modify it
164 under the same terms as Perl itself.
169 1; # End of Equinox::Migration::MapDrivenXMLProc