SOAPClient.pm

filter: Statementstmt 32.9% 31 / 94 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 52.9% 9 / 17 Podpod 100% 7 / 7 totaltotal 27.0% 47 / 174 CC 27 SCAR 38.2
CC
27
Cov
21%
new
110.0
_soap_query
72.0
update
30.0
CRAP 45.7
« Writer.pm ↑ Summary Source.pm »
1 package PICA::SOAPClient;
2 {
3 4 $PICA::SOAPClient::VERSION = '0.585';
4 }
5 #ABSTRACT: PICA::Store via SOAP access (aka 'webcat')
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶use PICA::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use PICA::Store;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use SOAP::Lite; # +trace => 'debug';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use SOAP::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Cwd qw(cwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Encode qw(encode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 our @ISA=qw(PICA::Store);
18  
19  
20 0 ▶sub new {
Subroutine new: not called CC=10 SCAR=47.0
Pod documented
21 0 my ($class) = shift;
22 0 ▶ my ($soap, %params) = (@_ % 2) ? (@_) : (undef, @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 0 0 0
23 0 ▶ $params{SOAP} = $soap if defined $soap;
Branch: 1 branch
BranchTrueFalseTotal
if defined $soap 0 0 0
24  
25 PICA::Store::readconfigfile( \%params, $ENV{PICASTORE} )
26 0 ▶ if exists $params{config} or exists $params{conf} ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"config"} or exists $params{"conf"} 0 0 0
Condition0%0/3
exists $params{"config"} or exists $params{"conf"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $params{"config"} or exists $params{"conf"}
exists $params{"config"} exists $params{"conf"}
Truth table0%0/3
A or B
A= exists $params{"config"}B= exists $params{"conf"}
ABresult
1X1
011
000
27  
28 0 ▶ croak "Missing SOAP base url (webcat)" unless defined $params{webcat};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"webcat"} 0 0 0
29 0 ▶ $params{dbsid} = "" unless defined $params{dbsid};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"dbsid"} 0 0 0
30 0 ▶ $params{userkey} = "" unless defined $params{userkey};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"userkey"} 0 0 0
31 0 ▶ $params{language} = "en" unless defined $params{language};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"language"} 0 0 0
32 0 ▶ $params{password} = "" unless defined $params{password};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"password"} 0 0 0
33  
34 $soap = SOAP::Lite->uri('http://www.gbv.de/schema/webcat-1.0')
35 0 ->proxy($params{webcat});
36 # ->encoding('utf-8')
37 # ->on_fault(sub{})
38  
39 my $self = bless {
40 'soap' => $soap,
41 'format' => SOAP::Data->name( "format" )->type( string => "pp" ),
42 'rectype_title' => SOAP::Data->name( "rectype" )->type( string => "title" ),
43 'rectype_entry' => SOAP::Data->name( "rectype" )->type( string => "entry" ),
44 'baseurl' => $params{webcat},
45 0 }, $class;
46  
47 0 return $self->access( %params );
48 }
49  
50  
51 0 ▶sub get {
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
52 0 my ($self, $id) = @_;
53 0 my %result = $self->_soap_query( "get",
54 SOAP::Data->name( "ppn" )->type( string => $id )
55 );
56 0 ▶ $result{record} = PICA::Record->new($result{record}) if $result{record};
Branch: 1 branch
BranchTrueFalseTotal
if $result{"record"} 0 0 0
57 0 return %result;
58 }
59  
60  
61 0 ▶sub create {
Subroutine create: not called CC=4 SCAR=30.0
Pod documented
62 0 my ($self, $record) = @_;
63 0 ▶ croak('create needs a PICA::Record object')
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($record, "PICA::Record") 0 0 0
64 unless UNIVERSAL::isa($record,'PICA::Record');
65 0 my $rectype = $self->{"rectype_title"};
66  
67 0 my $sf = $record->subfield('002@$0');
68 0 ▶ $rectype = $self->{"rectype_entry"} if ($sf && $sf =~ /^T/); # authority record
Branch: 1 branch
BranchTrueFalseTotal
if $sf and $sf =~ /^T/ 0 0 0
Condition0%0/3
$sf and $sf =~ /^T/
!ll&&!rl&&r
000
MC/DC0%0/2
$sf and $sf =~ /^T/
$sf $sf =~ /^T/
Truth table0%0/3
A and B
A= $sfB= $sf =~ /^T/
ABresult
0X0
100
111
69  
70 0 my $recorddata = encode_utf8( $record->string );
71  
72 0 return $self->_soap_query( "create",
73 SOAP::Data->name( "record" )->type( string => $recorddata ),
74 $rectype
75 );
76 }
77  
78  
79 0 ▶sub update {
Subroutine update: not called CC=5 SCAR=34.0
Pod documented
80 0 my ($self, $id, $record, $version) = @_;
81 0 my $recorddata;
82 0 ▶ if ( UNIVERSAL::isa( $id, 'PICA::Record' ) ) { # TODO: Test this
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($id, 'PICA::Record')) { } 0 0 0
83 0 $version = $record;
84 0 $record = $id;
85 0 $id = $id->ppn;
86 0 $record->ppn( undef );
87 0 $recorddata = encode_utf8( $record->string );
88 0 $record->ppn($id);
89 } else {
90 0 ▶ croak('update needs an ID and a PICA::Record object')
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($record, "PICA::Record") 0 0 0
91 unless UNIVERSAL::isa ($record,'PICA::Record');
92 0 $recorddata = encode_utf8( $record->string );
93 }
94  
95 0 ▶ if (not defined $version) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $version) 0 0 0
96 0 my %current = $self->get( $id );
97 0 ▶ return %current unless $current{version};
Branch: 1 branch
BranchTrueFalseTotal
unless $current{"version"} 0 0 0
98 0 $version = $current{version};
99 }
100  
101 0 return $self->_soap_query( "update",
102 SOAP::Data->name("ppn")->type( string => $id ),
103 SOAP::Data->name("record")->type( string => $recorddata ),
104 SOAP::Data->name("version")->type( string => $version )
105 );
106 }
107  
108  
109 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
110 0 my ($self, $id) = @_;
111 0 return $self->_soap_query( "delete",
112 SOAP::Data->name( "ppn" )->type( string => $id )
113 );
114 }
115  
116  
117 0 ▶sub access {
Subroutine access: not called CC=3 SCAR=24.8
Pod documented
118 0 my ($self, %params) = @_;
119  
120 0 for my $key (qw(userkey password dbsid language)) {
121 $self->{$key} =
122 SOAP::Data->name( $key => $params{$key} )->type('string')
123 0 ▶ if defined $params{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{$key} 0 0 0
124 }
125  
126 0 return $self;
127 }
128  
129  
130 0 ▶sub about {
Subroutine about: not called CC=1 SCAR=6.9
Pod documented
131 0 my $self = shift;
132 0 return "CWS Webcat: " . $self->{baseurl};
133 }
134  
135  
136  
137 0 ▶sub _soap_query {
Subroutine _soap_query: not called CC=8 SCAR=42.8
138 0 my ($self, $operation, @params) = @_;
139  
140 0 ▶ push @params, $self->{"format"} unless $operation eq "delete";
Branch: 1 branch
BranchTrueFalseTotal
unless $operation eq "delete" 0 0 0
141 0 push @params, ($self->{dbsid}, $self->{userkey}, $self->{language});
142 0 ▶ push @params, $self->{password} if defined $self->{password};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"password"} 0 0 0
143  
144 0 my $response = $self->{soap}->$operation( @params );
145  
146 0 my %result;
147 0 ▶ if (!$response) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $response) { } 0 0 0
elsif ($response->fault) { } 0 0 0
148 0 $result{errorcode} = "1";
149 0 $result{errormessage} = "No response to SOAP operation '$operation'.";
150 } elsif ($response->fault) {
151 0 $result{errorcode} = $response->faultcode;
152 0 $result{errormessage} = $response->faultstring;
153 0 chomp $result{errormessage};
154 } else {
155 0 ▶ $result{id} = $response->valueof("//ppn") if defined $response->valueof("//ppn");
Branch: 1 branch
BranchTrueFalseTotal
if defined $response->valueof("//ppn") 0 0 0
156 0 ▶ $result{record} = PICA::Record->new( $response->valueof("//record") )
Branch: 1 branch
BranchTrueFalseTotal
if defined $response->valueof("//record") 0 0 0
157 if defined $response->valueof("//record");
158 0 ▶ $result{version} = $response->valueof("//version")
Branch: 1 branch
BranchTrueFalseTotal
if defined $response->valueof("//version") 0 0 0
159 if defined $response->valueof("//version");
160 }
161  
162 0 return %result;
163 }
164  
165 4 1;
166  
167 __END__
« Writer.pm ↑ Summary Source.pm »