Client.pm

filter: Statementstmt 92.4% 49 / 53 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 91.5% 65 / 71 CC 3 SCAR 3.9
CC
3
Cov
89%
_call_remote
3.2
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« Serializer/Binary.pm ↑ Summary Serializer/Date.pm »
1 package Hessian::Client;
2  
3 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 23 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 23 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 23 ▶use Contextual::Return;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 23 ▶use Hessian::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 23 ▶use Hessian::Translator;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 23 ▶use Class::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 {
13 23 my %service : ATTR(:name<service>);
14 23 my %version : ATTR(:get<version> :init_arg<version>);
15 23 my %hessian_translator : ATTR(:get<translator> :set<translator>);
16  
17 2 ▶ sub BUILD { #{{{
Subroutine BUILD: called CC=1 SCAR=0.0
Pod documented
18 2 my ( $self, $id, $args ) = @_;
19 2 my $hessian = Hessian::Translator->new( version => $args->{version} );
20 2 $self->set_translator($hessian);
21 }
22  
23 2 ▶ sub AUTOMETHOD { #{{{
Subroutine AUTOMETHOD: called CC=1 SCAR=0.0
Pod documented
24 2 my ( $self, $id, @args ) = @_;
25 2 my $method_name = $_;
26  
27 2 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
28 2 my $datastructure = {
29 call => {
30 method => $method_name,
31 arguments => \@args
32  
33 },
34 };
35 2 return $self->_call_remote($datastructure);
36 }
37  
38 2 }
39  
40 2 ▶ sub _call_remote { #{{{
Subroutine _call_remote: called CC=3 SCAR=11.8
41 2 my ( $self, $datastructure ) = @_;
42 2 my $service = $self->get_service();
43 2 ▶ ServiceException->throw( error => "No service defined." )
Branch: 1 branch
BranchTrueFalseTotal
unless $service 0 2 2
44 unless $service;
45 2 my $request = HTTP::Request->new( 'POST', $service );
46 2 my $hessian = $self->get_translator();
47 2 $hessian->serializer();
48 2 my $hessian_string = $hessian->serialize_message($datastructure);
49 2 $request->content($hessian_string);
50 2 my $agent = LWP::UserAgent->new();
51 2 my $response = $agent->request($request);
52  
53 2 ▶ if ( $response->is_success() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 0 2 2
54 0 my $content = $response->content();
55 0 $hessian->input_string($content);
56 0 my $processed = $hessian->process_message();
57 0 return $processed;
58 }
59 2 ServiceException->throw( error => "No reponse from " . $service );
60  
61 }
62  
63 }
64  
65 23 "one, but we're not the same";
66  
67 __END__
« Serializer/Binary.pm ↑ Summary Serializer/Date.pm »