blib/lib/Net/FTP/Path/Iter/Entry.pm

filter: Statementstmt 91.8% 56 / 61 Branchbran 61.5% 16 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 100% 1 / 1 totaltotal 85.2% 87 / 102 SCAR 27.8
CC
15
Cov
83%
_statit
13.9
_get_entries
6.1
BUILD
2.0
CRAP 16.2
↑ Summary blib/lib/Net/FTP/Path/Iter/Dir.pm »
1 package Net::FTP::Path::Iter::Entry;
2  
3 5 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: Class representing a Filesystem Entry
6  
7 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 our $VERSION = '0.06';
11  
12 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Fcntl qw[ :mode ];
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 ▶use File::Listing qw[ parse_dir ];
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 use overload
20 '-X' => '_statit',
21 14 ▶ 'bool' => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 14 ▶ '""' => sub { $_[0]->{path} },
Subroutine __ANON__: called CC=1 SCAR=0.0
23 5 ▶ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 5 use Class::Tiny qw[
26 name type size mtime mode parent server path
27 5 ▶], { _has_attrs => 0 };
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38 sub BUILD {
39  
40 14 ▶ my $self = shift;
Subroutine BUILD: called CC=2 SCAR=6.9
Pod documented
41 14 ▶ $self->_retrieve_attrs
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_attrs 1 13 14
42 unless $self->_has_attrs;
43 }
44  
45 sub _statit {
46  
47 33 ▶ my $self = shift;
Subroutine _statit: called CC=9 SCAR=26.3
48 33 my $op = shift;
49  
50 33 ▶ $self->_retrieve_attrs
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_attrs 0 33 33
51 unless $self->_has_attrs;
52  
53 33 ▶ if ( $op eq 'd' ) { return $self->is_dir }
Branch: 7 branches
BranchTrueFalseTotal
if ($op eq 'd') { } 14 19 33
elsif ($op eq 'f') { } 0 19 19
elsif ($op eq 's') { } 0 19 19
elsif ($op eq 'z') { } 0 19 19
elsif ($op eq 'r') { } 5 14 19
elsif ($op eq 'R') { } 0 14 14
elsif ($op eq 'l') { } 14 0 14
54  
55 0 elsif ( $op eq 'f' ) { return $self->is_file }
56  
57 0 elsif ( $op eq 's' ) { return $self->size }
58  
59 0 elsif ( $op eq 'z' ) { return $self->size != 0 }
60  
61 5 elsif ( $op eq 'r' ) { return S_IROTH & $self->mode }
62  
63 0 elsif ( $op eq 'R' ) { return S_IROTH & $self->mode }
64  
65 14 elsif ( $op eq 'l' ) { return 0 }
66  
67 0 else { croak( "unsupported file test: -$op\n" ) }
68  
69 }
70  
71 sub _get_entries {
72  
73 5 ▶ my ( $self, $path ) = @_;
Subroutine _get_entries: called CC=6 SCAR=18.2
74  
75 5 my $server = $self->server;
76  
77 5 my $pwd = $server->pwd;
78  
79 # on some ftp servers, if $path is a symbolic link, dir($path)
80 # willl return a listing of $path's own entry, not of its
81 # contents. as a work around, explicitly cwd($path),
82 # get the listing, then restore the working directory
83  
84 5 my @entries;
85 5 eval {
86 5 ▶ $server->cwd( $path )
Branch: 1 branch
BranchTrueFalseTotal
$server->cwd($path) or croak("unable to chdir to ", $path, "\n") 0 5 5
87 or croak( "unable to chdir to ", $path, "\n" );
88  
89 5 ▶ my $listing = $server->dir( '.' )
Branch: 1 branch
BranchTrueFalseTotal
my $listing = $server->dir(".") or croak("error listing $path") 0 5 5
90 or croak( "error listing $path" );
91  
92 5 for my $entry ( parse_dir( $listing ) ) {
93  
94 13 my %attr;
95 13 @attr{qw[ name type size mtime mode]} = @$entry;
96 13 $attr{parent} = $path;
97 13 $attr{_has_attrs} = 1;
98  
99 13 push @entries, \%attr;
100  
101 }
102 };
103  
104 5 my $err = $@;
105  
106 5 ▶ $server->cwd( $pwd )
Branch: 1 branch
BranchTrueFalseTotal
$server->cwd($pwd) or croak("unable to return to directory: $pwd\n") 0 5 5
107 or croak( "unable to return to directory: $pwd\n" );
108  
109 5 ▶ croak( $err ) if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 5 5
110  
111  
112 5 return \@entries;
113  
114 }
115  
116 #
117 # This file is part of Net-FTP-Path-Iter
118 #
119 # This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.
120 #
121 # This is free software, licensed under:
122 #
123 # The GNU General Public License, Version 3, June 2007
124 #
125  
126 5 1;
127  
128 __END__
↑ Summary blib/lib/Net/FTP/Path/Iter/Dir.pm »