Iter/Entry.pm

filter: Statementstmt 91.8% 56 / 61 Branchbran 61.5% 16 / 26 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 14 / 14 Podpod 100% 1 / 1 totaltotal 82.2% 88 / 107 CC 16 SCAR 18.9
CC
16
Cov
81%
_statit
13.9
_get_entries
7.5
BUILD
2.0
CRAP 6.6
« Iter/Dir.pm ↑ Summary Iter.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.07';
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 5 ▶ '-X' => '_statit',
Subroutine BEGIN: called CC=1 SCAR=0.0
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 fallback => !!1,
24 5 ;
25  
26 5 ▶use Class::Tiny qw[
Subroutine BEGIN: called CC=1 SCAR=0.0
27 name type size mtime mode parent server path
28 5 ], { _has_attrs => 0 };
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39 14 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod documented
40  
41 14 my $self = shift;
42 14 ▶ $self->_retrieve_attrs
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_attrs 1 13 14
43 unless $self->_has_attrs;
44 }
45  
46 33 ▶sub _statit {
Subroutine _statit: called CC=9 SCAR=26.3
47  
48 33 my $self = shift;
49 33 my $op = shift;
50  
51 33 ▶ $self->_retrieve_attrs
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_attrs 0 33 33
52 unless $self->_has_attrs;
53  
54 ## no critic ( ControlStructures::ProhibitCascadingIfElse )
55 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
56  
57 0 elsif ( $op eq 'f' ) { return $self->is_file }
58  
59 0 elsif ( $op eq 's' ) { return $self->size }
60  
61 0 elsif ( $op eq 'z' ) { return $self->size != 0 }
62  
63 5 elsif ( $op eq 'r' ) { return S_IROTH & $self->mode }
64  
65 0 elsif ( $op eq 'R' ) { return S_IROTH & $self->mode }
66  
67 14 elsif ( $op eq 'l' ) { return 0 }
68  
69 0 else { croak( "unsupported file test: -$op" ) }
70  
71 }
72  
73 5 ▶sub _get_entries {
Subroutine _get_entries: called CC=7 SCAR=20.1
74  
75 5 my ( $self, $path ) = @_;
76  
77 5 my $server = $self->server;
78  
79 5 my $pwd = $server->pwd;
80  
81 # on some ftp servers, if $path is a symbolic link, dir($path)
82 # willl return a listing of $path's own entry, not of its
83 # contents. as a work around, explicitly cwd($path),
84 # get the listing, then restore the working directory
85  
86 5 my @entries;
87 my $err;
88 5 ▶ eval {
Condition33%1/3
eval { do { $server->cwd($path) or croak("unable to chdir to ", $path); my $listing = $server->dir(".") or croak("error listing $path"); foreach my $entry (&parse_dir($listing)) { my %attr; @attr{"name", "type", "size", "mtime", "mode"} = @$entry; $attr{"parent"} = $path; $attr{"_has_attrs"} = 1; push @entries, \%attr; } ; 1 } } // ($err = $@)
l!l&&r!l&&!r
500
MC/DC0%0/2
eval { do { $server->cwd($path) or croak("unable to chdir to ", $path); my $listing = $server->dir(".") or croak("error listing $path"); foreach my $entry (&parse_dir($listing)) { my %attr; @attr{"name", "type", "size", "mtime", "mode"} = @$entry; $attr{"parent"} = $path; $attr{"_has_attrs"} = 1; push @entries, \%attr; } ; 1 } } // ($err = $@)
eval { do { $server->cwd($path) or croak("unable to chdir to ", $path); my $listing = $server->dir(".") or croak("error listing $path"); foreach my $entry (&parse_dir($listing)) { my %attr; @attr{"name", "type", "size", "mtime", "mode"} = @$entry; $attr{"parent"} = $path; $attr{"_has_attrs"} = 1; push @entries, \%attr; } ; 1 } } ($err = $@)
Truth table33%1/3
A // B
A= eval { do { $server->cwd($path) or croak("unable to chdir to ", $path); my $listing = $server->dir(".") or croak("error listing $path"); foreach my $entry (&parse_dir($listing)) { my %attr; @attr{"name", "type", "size", "mtime", "mode"} = @$entry; $attr{"parent"} = $path; $attr{"_has_attrs"} = 1; push @entries, \%attr; } ; 1 } }B= ($err = $@)
ABresult
1X1
011
000
89 5 ▶ $server->cwd( $path )
Branch: 1 branch
BranchTrueFalseTotal
$server->cwd($path) or croak("unable to chdir to ", $path) 5 0 5
90 or croak( 'unable to chdir to ', $path );
91  
92 5 ▶ my $listing = $server->dir( q{.} )
Branch: 1 branch
BranchTrueFalseTotal
my $listing = $server->dir(".") or croak("error listing $path") 5 0 5
93 or croak( "error listing $path" );
94  
95 5 for my $entry ( parse_dir( $listing ) ) {
96  
97 13 my %attr;
98 13 @attr{qw[ name type size mtime mode]} = @$entry;
99 13 $attr{parent} = $path;
100 13 $attr{_has_attrs} = 1;
101  
102 13 push @entries, \%attr;
103  
104 }
105 5 1;
106 } // ( $err = $@ );
107  
108 5 ▶ $server->cwd( $pwd )
Branch: 1 branch
BranchTrueFalseTotal
$server->cwd($pwd) or croak("unable to return to directory: $pwd") 5 0 5
109 or croak( "unable to return to directory: $pwd" );
110  
111 5 ▶ croak( $err ) if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 0 5 5
112  
113 5 return \@entries;
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__
« Iter/Dir.pm ↑ Summary Iter.pm »