Net/OBEX/FTP.pm

filter: Statementstmt 29.5% 26 / 88 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 53.8% 7 / 13 Podpod 100% 5 / 5 totaltotal 26.2% 38 / 145 CC 21 SCAR 40.9
CC
21
Cov
21%
connect
110.0
cwd
90.0
get
12.0
CRAP 59.7
« Net/OBEX.pm ↑ Summary Net/OBEX/Response.pm »
1 package Net::OBEX::FTP;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '1.001002'; # VERSION
7  
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Net::OBEX;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use XML::OBEXFTP::FolderListing;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use base qw(Class::Data::Accessor);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 __PACKAGE__->mk_classaccessors( qw(
14 obex
15 response
16 error
17 pwd
18 xml
19 folders
20 files
21 )
22 );
23  
24 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
25 1 my $class = shift;
26  
27 1 my $self = bless {}, $class;
28 1 $self->obex( Net::OBEX->new );
29 1 $self->xml( XML::OBEXFTP::FolderListing->new );
30 1 return $self;
31 }
32  
33 0 ▶sub connect {
Subroutine connect: not called CC=10 SCAR=47.0
Pod documented
34 0 my $self = shift;
35 0 ▶ croak "Must have even number of arguments to connect()"
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 0 0
36 if @_ & 1;
37  
38 0 my %args = @_;
39 0 $args{ +lc } = delete $args{ $_ } for keys %args;
40  
41 croak "Missing `address` argument to connect()"
42 0 ▶ unless exists $args{address};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"address"} 0 0 0
43  
44 croak "Missing `port` argument to connect()"
45 0 ▶ unless exists $args{port};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"port"} 0 0 0
46  
47 0 %args = (
48 mtu => 4096,
49 version => "\x10",
50  
51 %args,
52 );
53  
54 0 $self->error(undef);
55  
56 0 my %response;
57  
58 0 my $obex = $self->obex;
59 $response{connect} = $obex->connect(
60 mtu => $args{mtu},
61 version => $args{version},
62 address => $args{address},
63 port => $args{port},
64 0 ▶ target => 'F9EC7BC4953C11D2984E525400DC9E09', # OBEX FTP UUID
Branch: 1 branch
BranchTrueFalseTotal
$response{"connect"} = $obex->connect("mtu", $args{"mtu"}, "version", $args{"version"}, "address", $args{"address"}, "port", $args{"port"}, "target", "F9EC7BC4953C11D2984E525400DC9E09") or return $self->_set_error('Failed to connect: ' . $obex->error) 0 0 0
65 ) or return $self->_set_error('Failed to connect: ' . $obex->error);
66  
67 0 ▶ $self->_is_success( \%response, 'connect' )
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_success(\%response, "connect") or return 0 0 0
68 or return;
69  
70 0 ▶ $response{set_path} = $obex->set_path
Branch: 1 branch
BranchTrueFalseTotal
$response{"set_path"} = $obex->set_path or return $self->_set_error('Failed to set path: ' . $obex->error) 0 0 0
71 or return $self->_set_error('Failed to set path: ' . $obex->error);
72  
73 0 ▶ $self->_is_success( \%response, 'set_path' )
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_success(\%response, "set_path") or return 0 0 0
74 or return;
75  
76 0 $self->pwd([]);
77  
78 0 ▶ $response{get} = $obex->get( type => 'x-obex/folder-listing' )
Branch: 1 branch
BranchTrueFalseTotal
$response{"get"} = $obex->get("type", "x-obex/folder-listing") or return $self->_set_error('Failed to get folder listing: ' . $obex->error) 0 0 0
79 or return $self->_set_error(
80 'Failed to get folder listing: ' . $obex->error
81 );
82  
83 0 my $xml = $self->xml;
84 0 $xml->parse($response{get}{body});
85 0 $self->folders( $xml->folders );
86 0 $self->files( $xml->files );
87 0 return $self->response( \%response );
88 }
89  
90 0 ▶sub cwd {
Subroutine cwd: not called CC=9 SCAR=45.0
Pod documented
91 0 my $self = shift;
92  
93 0 my %args;
94 0 ▶ if ( @_ & 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ & 1) { } 0 0 0
95 0 $args{path} = shift;
96 }
97 else {
98 0 %args = @_;
99 0 $args{ +lc } = delete $args{ $_ } for keys %args;
100 }
101  
102 0 $self->error(undef);
103  
104 0 my $obex = $self->obex;
105  
106 0 my %response;
107  
108 0 ▶ $response{set_path} = $obex->set_path( %args )
Branch: 1 branch
BranchTrueFalseTotal
$response{"set_path"} = $obex->set_path(%args) or return $self->_set_error('Failed to set path: ' . $obex->error) 0 0 0
109 or return $self->_set_error('Failed to set path: ' . $obex->error );
110  
111 0 ▶ $self->_is_success( \%response, 'set_path' )
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_success(\%response, "set_path") or return 0 0 0
112 or return;
113  
114 0 my $pwd_ref = $self->pwd;
115 0 ▶ if ( defined $args{path} and length $args{path} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args{'path'} and length $args{'path'}) { } 0 0 0
elsif (defined $args{'do_up'}) { } 0 0 0
Condition0%0/3
defined $args{"path"} and length $args{"path"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"path"} and length $args{"path"}
defined $args{"path"} length $args{"path"}
Truth table0%0/3
A and B
A= defined $args{"path"}B= length $args{"path"}
ABresult
0X0
100
111
116 0 push @$pwd_ref, $args{path};
117 }
118 elsif ( defined $args{do_up} ) {
119 0 pop @$pwd_ref;
120 }
121 else {
122 0 $pwd_ref = [];
123 }
124 0 $self->pwd( $pwd_ref );
125  
126 0 ▶ $response{get} = $obex->get( type => 'x-obex/folder-listing' )
Branch: 1 branch
BranchTrueFalseTotal
$response{"get"} = $obex->get("type", "x-obex/folder-listing") or return $self->_set_error('Failed to get folder listing: ' . $obex->error) 0 0 0
127 or return $self->_set_error(
128 'Failed to get folder listing: ' . $obex->error
129 );
130  
131 0 my $xml = $self->xml;
132  
133 0 $xml->parse( $response{get}{body} );
134 0 $self->files( $xml->files );
135 0 $self->folders( $xml->folders );
136  
137 0 return $self->response( \%response );
138 }
139  
140 0 ▶sub get {
Subroutine get: not called CC=3 SCAR=24.8
Pod documented
141 0 my ( $self, $what, $fh ) = @_;
142  
143 0 $self->error(undef);
144  
145 0 my $obex = $self->obex;
146 0 ▶ my $response_ref = $obex->get(
Branch: 2 branches
BranchTrueFalseTotal
my $response_ref = $obex->get("name", $what, defined $fh ? ("file", $fh) : ()) or return $self->_set_error('Failed to get: ' . $obex->error) 0 0 0
defined $fh ? : 0 0 0
147 name => $what,
148 defined $fh ? ( file => $fh ) : (),
149 ) or return $self->_set_error( 'Failed to get: ' . $obex->error );
150  
151 0 return $self->response( $response_ref );
152 }
153  
154 0 ▶sub _is_success {
Subroutine _is_success: not called CC=2 SCAR=17.9
155 0 my ( $self, $response_ref, $type ) = @_;
156 0 ▶ unless( $response_ref->{ $type }{info}{response_code} == 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response_ref->{$type}{"info"}{"response_code"} == 200) 0 0 0
157 my ($code, $meaning)
158 0 = @{ $response_ref->{ $type }{info} }{
159 0 qw( response_code response_code_meaning )
160 };
161  
162 0 $self->response( $response_ref );
163 0 $self->error( "Failed to connect: ($code) $meaning" );
164 0 return 0;
165 }
166 0 return 1
167 }
168  
169 0 ▶sub _set_error {
Subroutine _set_error: not called CC=1 SCAR=6.9
170 0 my ( $self, $error ) = @_;
171 0 $self->error( $error );
172 0 return;
173 }
174  
175 0 ▶sub close {
Subroutine close: not called CC=1 SCAR=6.9
Pod documented
176 0 my $self = shift;
177 0 $self->obex->close( @_ );
178 }
179  
180 2 1;
181  
182 __END__
« Net/OBEX.pm ↑ Summary Net/OBEX/Response.pm »