push lib into @INC
[Biblio-SIP2.git] / sc-emulator.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use IO::Socket::INET;
7 use autodie;
8
9 our $user     = 'sip2-user';
10 our $password = 'sip2-paasswd';
11 our $patron   = 200000000042;
12 our $barcode  = 1301132799;
13 our $loc      = 'FFZG';
14
15 require 'config.pl' if -e 'config.pl';
16
17 use SIP2;
18
19 our $sock = IO::Socket::INET->new( '10.60.0.251:6001' );
20
21
22 sub sip2 {
23         my ( $send, $patt ) = @_;
24         SIP2::dump_message '>>>>', $send;
25         print $sock "$send\r\n";
26         $sock->flush;
27
28 #       local $/ = "\r";
29
30         my $in = <$sock>;
31         SIP2::dump_message '<<<<', $in;
32         die "expected $patt" unless $in =~ $patt;
33 }
34
35 # login
36 sip2 "9300CN$user|CO$password|" => qr/^941/;
37
38 # SC Status
39 sip2 "9900302.00" => qr/^98/;
40
41 # Patron Information
42 sip2 "6300020091214    085452          AO$loc|AA$patron|AC$password|" => qr/^64/;
43
44 # Checkout
45 sip2 "11YN20091214    124436                  AO$loc|AA$patron|AB$barcode|AC$password|BON|BIN|" => qw/12/;
46
47 # Checkin
48 sip2 "09N20091214    08142820091214    081428AP|AO$loc|AB$barcode|AC|BIN|" => qr/^10/;
49