| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | croak "Missing `port` argument to connect()" | ||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | unless exists $args{port}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 65 | ) or return $self->_set_error('Failed to connect: ' . $obex->error); | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | $self->_is_success( \%response, 'connect' ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | or return; | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $response{set_path} = $obex->set_path | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 71 | or return $self->_set_error('Failed to set path: ' . $obex->error); | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $self->_is_success( \%response, 'set_path' ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 74 | or return; | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 0 | $self->pwd([]); | |||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $response{get} = $obex->get( type => 'x-obex/folder-listing' ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 109 | or return $self->_set_error('Failed to set path: ' . $obex->error ); | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $self->_is_success( \%response, 'set_path' ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 112 | or return; | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | 0 | my $pwd_ref = $self->pwd; | |||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ( defined $args{path} and length $args{path} ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $args{"path"} and length $args{"path"}
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"}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||