--- COBISS.pm 2009/06/20 19:42:00 5 +++ COBISS.pm 2010/10/22 21:31:08 14 @@ -5,7 +5,7 @@ use WWW::Mechanize; use MARC::Record; -use File::Slurp; +use Data::Dump qw/dump/; binmode STDOUT, ':utf8'; @@ -17,7 +17,7 @@ }, 205 => { a => [ 250 , 'a' ] }, 210 => { - a => [ 250 , 'a' ], + a => [ 260 , 'a' ], c => [ 260 , 'b' ], d => [ 260 , 'c' ], }, @@ -64,11 +64,6 @@ }; -sub usemap { - my $f = shift || die; - $usemap->{$f}; -} - sub search { my ( $self, $query ) = @_; @@ -76,19 +71,19 @@ my $url = 'http://cobiss.izum.si/scripts/cobiss?ukaz=GETID&lani=en'; -diag "# get $url"; +diag "get $url"; $mech->get( $url ); -diag "# got session"; +diag "got session"; $mech->follow_link( text_regex => qr/union/ ); -diag "# switch to advanced form (select)"; +diag "switch to advanced form (select)"; $mech->follow_link( url_regex => qr/mode=3/ ); -diag "# submit search $query"; +diag "submit search $query"; $mech->submit_form( fields => { @@ -104,61 +99,101 @@ return; } -diag "# got $hits results, get first one"; +diag "got $hits results, get first one"; $mech->follow_link( url_regex => qr/ukaz=DISP/ ); -diag "# in COMARC format"; +diag "in COMARC format"; $mech->follow_link( url_regex => qr/fmt=13/ ); } -sub fetch_marc { - my ($self) = @_; +sub fetch_rec { + my ($self,$format) = @_; + + $format ||= 'unimarc'; + + die "unknown format: $format" unless $format =~ m{(uni|us)marc}; my $comarc; - if ( $mech->content =~ m{
\s*(.+?(\d+\.)\s+ID=(\d+).+?)\s*}s ) { + if ( $mech->content =~ m{
\s*(.+?(\d+)\.\s+ID=(\d+).+?)\s*}s ) { my $comarc = $1; my $nr = $2; my $id = $3; -diag "# fetch_marc $nr [$id]"; +diag "fetch_marc $nr [$id] $format"; $comarc =~ s{?b>}{}gs; $comarc =~ s{]*>}{