« blib/lib/Test/Smoke/App/ConfigSmoke/Mail.pm
↑ Summary
blib/lib/Test/Smoke/App/ConfigSmoke/WriteSmokeScript.pm »
| 1 | package Test::Smoke::FTPClient; | ||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Net::FTP; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Cwd; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use File::Path; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use File::Spec::Functions qw( :DEFAULT abs2rel rel2abs ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Test::Smoke::Util qw( clean_filename time_in_hhmm ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '0.011'; | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 1 | my %CONFIG = ( | |||||||||||||||||||||||||||||||||
| 13 | df_fhost => undef, | ||||||||||||||||||||||||||||||||||
| 14 | df_fport => 21, | ||||||||||||||||||||||||||||||||||
| 15 | df_fuser => 'anonymous', | ||||||||||||||||||||||||||||||||||
| 16 | df_fpasswd => '', | ||||||||||||||||||||||||||||||||||
| 17 | df_v => 1, | ||||||||||||||||||||||||||||||||||
| 18 | df_fpassive => 1, | ||||||||||||||||||||||||||||||||||
| 19 | df_ftype => undef, | ||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | valid => [qw( fport fuser fpasswd fpassive ftype )], | ||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||
| 23 | 1 | my @sn = qw( B KB MB GB TB ); | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | BEGIN { eval qq/use Time::HiRes qw( time ) / } | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | Test::Smoke::FTPClient - Implement a mirror like object | ||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | use Test::Smoke::FTPClient; | ||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | my $server = 'ftp.example.com'; | ||||||||||||||||||||||||||||||||||
| 36 | my $fc = Test::Smoke::FTPClient->new( $server ); | ||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | my $sdir = '/'; | ||||||||||||||||||||||||||||||||||
| 39 | my $ddir = '~/perlsmoke/perl-current'; | ||||||||||||||||||||||||||||||||||
| 40 | my $cleanup = 1; # like --delete for rsync | ||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | $fc->connect; | ||||||||||||||||||||||||||||||||||
| 43 | $fc->mirror( $sdir, $ddir, $cleanup ); | ||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | $fc->bye; | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | This solution is B<slow>, you'd better use B<rsync>! | ||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | =head2 Test::Smoke::FTPClient->new( $server[, %options] ) | ||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | Create a new object with option checking: | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | * fuser | ||||||||||||||||||||||||||||||||||
| 58 | * fpasswd | ||||||||||||||||||||||||||||||||||
| 59 | * v | ||||||||||||||||||||||||||||||||||
| 60 | * fpassive | ||||||||||||||||||||||||||||||||||
| 61 | * ftype | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | =cut | ||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 66 | 3 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | 3 | my $server = shift; | |||||||||||||||||||||||||||||||||
| 69 | 3 | my $port = shift; | |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 3 | ▶ | unless ( $server ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 72 | 0 | require Carp; | |||||||||||||||||||||||||||||||||
| 73 | 0 | Carp::croak( "Usage: Test::Smoke::FTPClient->new( \$server, \$port )" ); | |||||||||||||||||||||||||||||||||
| 74 | }; | ||||||||||||||||||||||||||||||||||
| 75 | 3 | ▶ | unless ( $port ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 76 | 0 | require Carp; | |||||||||||||||||||||||||||||||||
| 77 | 0 | Carp::croak( "Usage: Test::Smoke::FTPClient->new( \$server, \$port )" ); | |||||||||||||||||||||||||||||||||
| 78 | }; | ||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | my %args_raw = @_ ? UNIVERSAL::isa( $_[0], 'HASH' ) ? %{ $_[0] } : @_ : (); | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | my %args = map { | ||||||||||||||||||||||||||||||||||
| 84 | 3 | ( my $key = $_ ) =~ s/^-?(.+)$/lc $1/e; | |||||||||||||||||||||||||||||||||
| 85 | 15 | ( $key => $args_raw{ $_ } ); | |||||||||||||||||||||||||||||||||
| 86 | } keys %args_raw; | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | my %fields = map { | ||||||||||||||||||||||||||||||||||
| 89 | 18 | ▶ | my $value = exists $args{$_} ? $args{ $_ } : $CONFIG{ "df_$_" }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 90 | 18 | ( $_ => $value ) | |||||||||||||||||||||||||||||||||
| 91 | 3 | } ( v => @{ $CONFIG{ valid } } ); | |||||||||||||||||||||||||||||||||
| 92 | 3 | $fields{fhost} = $server; | |||||||||||||||||||||||||||||||||
| 93 | 3 | $fields{fport} = $port; | |||||||||||||||||||||||||||||||||
| 94 | 3 | ▶ | $fields{v} ||= 0; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fields{"v"} ||= 0
MC/DC0%0/1
$fields{"v"} ||= 0
$fields{"v"}
Truth table50%1/2
A
A= $fields{"v"}
| |||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | 3 | return bless \%fields, $class; | |||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||
| 100 | =head2 $ftpclient->connect( ) | ||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | Returns true for success after connecting and login. | ||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 3 | ▶ | sub connect { | ||||||||||||||||||||||||||||||||
|
Subroutine
connect: called CC=10 SCAR=32.7
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 107 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 3 | ▶ | $self->{v} and print "Connecting to '$self->{fhost}' with port '$self->{fport}' "; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 110 | $self->{client} = Net::FTP->new( $self->{fhost}, | ||||||||||||||||||||||||||||||||||
| 111 | Port => $self->{fport}, | ||||||||||||||||||||||||||||||||||
| 112 | Passive => $self->{fpassive}, | ||||||||||||||||||||||||||||||||||
| 113 | 3 | Debug => ( $self->{v} > 2 ), | |||||||||||||||||||||||||||||||||
| 114 | ); | ||||||||||||||||||||||||||||||||||
| 115 | 3 | ▶ | unless ( $self->{client} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 116 | 0 | $self->{error} = $@; | |||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | $self->{v} and print "NOT OK ($self->{error})\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 118 | 0 | return; | |||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||
| 120 | 3 | ▶ | $self->{v} and print "OK\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | 3 | ▶ | $self->{v} and print "Authenticating "; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 123 | 3 | ▶ | unless ( $self->{client}->login( $self->{fuser}, $self->{fpasswd} ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $self->{error} = $@ || | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || "Could not login($self->{'fuser'}) on $self->{'fhost'}"
MC/DC0%0/1
$@ || "Could not login($self->{'fuser'}) on $self->{'fhost'}"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||
| 125 | "Could not login($self->{fuser}) on $self->{fhost}"; | ||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | $self->{v} and print "NOT OK ($self->{error})\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 127 | 0 | return; | |||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||
| 129 | 3 | ▶ | $self->{v} and print "OK\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | 3 | return 1; | |||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||
| 134 | =head2 $client->mirror( $sdir, $ddir ) | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | Set-up the environment and call C<__do_mirror()> | ||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||
| 140 | 3 | ▶ | sub mirror { | ||||||||||||||||||||||||||||||||
|
Subroutine
mirror: called CC=12 SCAR=27.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 141 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 142 | 3 | ▶ | return unless UNIVERSAL::isa( $self->{client}, 'Net::FTP' ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | 3 | my( $fdir, $ddir, $cleanup ) = @_; | |||||||||||||||||||||||||||||||||
| 145 | 3 | my $cwd = cwd(); | |||||||||||||||||||||||||||||||||
| 146 | # Get the local directory sorted | ||||||||||||||||||||||||||||||||||
| 147 | 3 | $ddir = rel2abs( $ddir ); | |||||||||||||||||||||||||||||||||
| 148 | 3 | ▶ | mkpath( $ddir, $self->{v} ) unless -d $ddir; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 149 | 3 | ▶ | unless ( chdir $ddir ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 150 | 0 | $self->{error} = "Cannot chdir($ddir): $!"; | |||||||||||||||||||||||||||||||||
| 151 | 0 | return; | |||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||
| 153 | 3 | my $lroot = catdir( $ddir, updir ); | |||||||||||||||||||||||||||||||||
| 154 | 3 | ▶ | chdir $lroot and $lroot = cwd() and chdir $cwd; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
chdir $lroot and $lroot = cwd()
MC/DC0%0/2
chdir $lroot and $lroot = cwd()
chdir $lroot
$lroot = cwd()
Truth table33%1/3
A and B
A= chdir $lrootB= $lroot = cwd()
| |||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | 3 | ▶ | if ( $self->{ftype} && $self->{client}->can( $self->{ftype} ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"ftype"} and $self->{"client"}->can($self->{"ftype"})
MC/DC0%0/2
$self->{"ftype"} and $self->{"client"}->can($self->{"ftype"})
$self->{"ftype"}
$self->{"client"}->can($self->{"ftype"})
Truth table33%1/3
A and B
A= $self->{"ftype"}B= $self->{"client"}->can($self->{"ftype"})
| |||||||||||||||||||||||||||||||||||
| 157 | 0 | my $ftype = $self->{ftype}; | |||||||||||||||||||||||||||||||||
| 158 | 0 | eval '$self->{client}->$ftype'; | |||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||
| 160 | 3 | my( $totsize, $tottime ) = ( 0, 0 ); | |||||||||||||||||||||||||||||||||
| 161 | 3 | ▶ | $self->{v} and print "Start mirror to: $ddir\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 162 | 3 | my $start = time; | |||||||||||||||||||||||||||||||||
| 163 | my $ret = __do_mirror( $self->{client}, $fdir, $ddir, $lroot, | ||||||||||||||||||||||||||||||||||
| 164 | 3 | $self->{v}, $cleanup, $totsize, $tottime ); | |||||||||||||||||||||||||||||||||
| 165 | 3 | my $ttime = time - $start; | |||||||||||||||||||||||||||||||||
| 166 | 3 | ▶ | $tottime or $tottime = 0.001; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 167 | 3 | my $speed = $totsize / $tottime; | |||||||||||||||||||||||||||||||||
| 168 | 3 | my $ord = 0; | |||||||||||||||||||||||||||||||||
| 169 | 3 | ▶ | while ( $speed > 1024 ) { $speed /= 1024; $ord++ } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 170 | 3 | ▶ | $self->{v} and printf "Mirror took %s \@ %.3f %s\n", | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 171 | time_in_hhmm( $ttime ), $speed, $sn[ $ord ]; | ||||||||||||||||||||||||||||||||||
| 172 | 3 | chdir $cwd; | |||||||||||||||||||||||||||||||||
| 173 | 3 | return $ret; | |||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||
| 176 | =head2 $client->bye | ||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||
| 178 | Disconnect from the FTP-server and cleanup the Net::FTP client; | ||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||
| 180 | =cut | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | sub bye { | ||||||||||||||||||||||||||||||||
|
Subroutine
bye: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 183 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 184 | 0 | $self->{client}->quit; | |||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||
| 187 | =head2 Test::Smoke::FTPClient->config( $key[, $value] ) | ||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||
| 189 | C<config()> is an interface to the package lexical C<%CONFIG>, | ||||||||||||||||||||||||||||||||||
| 190 | which holds all the default values for the C<new()> arguments. | ||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||
| 192 | With the special key B<all_defaults> this returns a reference | ||||||||||||||||||||||||||||||||||
| 193 | to a hash holding all the default values. | ||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | =cut | ||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub config { | ||||||||||||||||||||||||||||||||
|
Subroutine
config: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 198 | 0 | my $dummy = shift; | |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | 0 | my $key = lc shift; | |||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if ( $key eq 'all_defaults' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 203 | my %default = map { | ||||||||||||||||||||||||||||||||||
| 204 | 0 | my( $pass_key ) = $_ =~ /^df_(.+)/; | |||||||||||||||||||||||||||||||||
| 205 | 0 | ( $pass_key => $CONFIG{ $_ } ); | |||||||||||||||||||||||||||||||||
| 206 | } grep /^df_/ => keys %CONFIG; | ||||||||||||||||||||||||||||||||||
| 207 | 0 | return \%default; | |||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | return undef unless exists $CONFIG{ "df_$key" }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | $CONFIG{ "df_$key" } = shift if @_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||
| 214 | 0 | return $CONFIG{ "df_$key" }; | |||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||
| 217 | =head2 __do_mirror( $ftp, $ftpdir, $localdir, $lroot, $verbose, $cleanup ) | ||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | Recursive sub to mirror a tree from an FTP server. | ||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||
| 221 | =cut | ||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||||||||
| 224 | 1 | my $mirror_ok = 1; | |||||||||||||||||||||||||||||||||
| 225 | 34 | ▶ | sub __do_mirror { | ||||||||||||||||||||||||||||||||
|
Subroutine
__do_mirror: called CC=41 SCAR=40.0
| |||||||||||||||||||||||||||||||||||
| 226 | 34 | my( $ftp, $ftpdir, $localdir, $lroot, $verbose, $cleanup, | |||||||||||||||||||||||||||||||||
| 227 | $totsize, $tottime ) = @_; | ||||||||||||||||||||||||||||||||||
| 228 | 34 | ▶ | $verbose ||= 0; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$verbose ||= 0
MC/DC0%0/1
$verbose ||= 0
$verbose
Truth table50%1/2
A
A= $verbose
| |||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||
| 230 | 34 | $ftp->cwd( $ftpdir ); | |||||||||||||||||||||||||||||||||
| 231 | 34 | ▶ | $verbose > 1 and printf "Entering %s\n", $ftp->pwd; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||
| 233 | 34 | my @list = dirlist( $ftp, $verbose ); | |||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||
| 235 | 34 | foreach my $entry ( sort { $a->{type} cmp $b->{type} || | |||||||||||||||||||||||||||||||||
| 236 | 215 | ▶ | $a->{name} cmp $b->{name} } @list ) { | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Test::Smoke::FTPClient::a->{'type'} cmp $Test::Smoke::FTPClient::b->{'type'} || $Test::Smoke::FTPClient::a->{'name'} cmp $Test::Smoke::FTPClient::b->{'name'}
MC/DC0%0/2
$Test::Smoke::FTPClient::a->{'type'} cmp $Test::Smoke::FTPClient::b->{'type'} || $Test::Smoke::FTPClient::a->{'name'} cmp $Test::Smoke::FTPClient::b->{'name'}
$Test::Smoke::FTPClient::a->{'type'} cmp $Test::Smoke::FTPClient::b->{'type'}
$Test::Smoke::FTPClient::a->{'name'} cmp $Test::Smoke::FTPClient::b->{'name'}
Truth table66%2/3
A || B
A= $Test::Smoke::FTPClient::a->{'type'} cmp $Test::Smoke::FTPClient::b->{'type'}B= $Test::Smoke::FTPClient::a->{'name'} cmp $Test::Smoke::FTPClient::b->{'name'}
| |||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||
| 238 | 145 | ▶ | if ( $entry->{type} eq 'l' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 239 | } elsif ( $entry->{type} eq 'd' ) { | ||||||||||||||||||||||||||||||||||
| 240 | 105 | ▶ | $entry->{name} =~ m/^\.\.?$/ and next; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 241 | 37 | my $new_locald = File::Spec->catdir( $localdir, $entry->{name} ); | |||||||||||||||||||||||||||||||||
| 242 | 37 | ▶ | unless ( -d $new_locald ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 243 | 22 | ▶ | eval { mkpath( $new_locald, $verbose, $entry->{mode} ) } or | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 244 | return; | ||||||||||||||||||||||||||||||||||
| 245 | 22 | ▶ | $@ and return; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||
| 247 | 37 | chdir $new_locald; | |||||||||||||||||||||||||||||||||
| 248 | $mirror_ok &&= __do_mirror( $ftp, $entry->{name}, | ||||||||||||||||||||||||||||||||||
| 249 | 37 | ▶ | $new_locald, $lroot, $verbose, | ||||||||||||||||||||||||||||||||
|
Condition100%3/3
$mirror_ok &&= __do_mirror($ftp, $entry->{"name"}, $new_locald, $lroot, $verbose, $cleanup, $totsize, $tottime)
MC/DC100%2/2
$mirror_ok &&= __do_mirror($ftp, $entry->{"name"}, $new_locald, $lroot, $verbose, $cleanup, $totsize, $tottime)
$mirror_ok
__do_mirror($ftp, $entry->{"name"}, $new_locald, $lroot, $verbose, $cleanup, $totsize, $tottime)
Truth table100%3/3
A &&= B
A= $mirror_okB= __do_mirror($ftp, $entry->{"name"}, $new_locald, $lroot, $verbose, $cleanup, $totsize, $tottime)
| |||||||||||||||||||||||||||||||||||
| 250 | $cleanup, $totsize, $tottime ); | ||||||||||||||||||||||||||||||||||
| 251 | 37 | ▶ | $entry->{time} ||= $entry->{date}; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$entry->{"time"} ||= $entry->{"date"}
MC/DC0%0/2
$entry->{"time"} ||= $entry->{"date"}
$entry->{"time"}
$entry->{"date"}
Truth table33%1/3
A ||= B
A= $entry->{"time"}B= $entry->{"date"}
| |||||||||||||||||||||||||||||||||||
| 252 | 37 | utime $entry->{time}, $entry->{time}, $new_locald; | |||||||||||||||||||||||||||||||||
| 253 | 37 | $ftp->cwd( '..' ); | |||||||||||||||||||||||||||||||||
| 254 | 37 | chdir File::Spec->updir; | |||||||||||||||||||||||||||||||||
| 255 | 37 | ▶ | $verbose > 1 and print "Leaving '$entry->{name}' [$new_locald]\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 256 | } else { | ||||||||||||||||||||||||||||||||||
| 257 | 40 | $entry->{time} = $ftp->mdtm( $entry->{name} ); #slow down | |||||||||||||||||||||||||||||||||
| 258 | 40 | my $fname = clean_filename( $entry->{name} ); | |||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||
| 260 | 40 | my $destname = catfile( $localdir, canonpath($fname) ); | |||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||
| 262 | 40 | my $skip; | |||||||||||||||||||||||||||||||||
| 263 | 40 | ▶ | if ( -e $destname ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 264 | 19 | my( $l_size, $l_mode, $l_time ) = (stat $destname)[7, 2, 9]; | |||||||||||||||||||||||||||||||||
| 265 | 19 | $l_mode &= 07777; | |||||||||||||||||||||||||||||||||
| 266 | $skip = ($l_size == $entry->{size}) && | ||||||||||||||||||||||||||||||||||
| 267 | ($l_mode == $entry->{mode}) && | ||||||||||||||||||||||||||||||||||
| 268 | 19 | ▶ | ($l_time == $entry->{time}); | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$l_size == $entry->{'size'} && $l_mode == $entry->{'mode'} && $l_time == $entry->{'time'}
$l_size == $entry->{"size"} and $l_mode == $entry->{"mode"}
MC/DC0%0/3
$l_size == $entry->{'size'} && $l_mode == $entry->{'mode'} && $l_time == $entry->{'time'}
$l_size == $entry->{"size"}
$l_mode == $entry->{"mode"}
$l_time == $entry->{'time'}
Truth table25%1/4
A and B && C
A= $l_size == $entry->{"size"}B= $l_mode == $entry->{"mode"}C= $l_time == $entry->{'time'}
| |||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||
| 270 | 40 | ▶ | unless ( $skip ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 271 | 21 | ▶ | 1 while unlink $destname; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 272 | $verbose and printf "%s: %d/", abs2rel( $destname, $lroot ), | ||||||||||||||||||||||||||||||||||
| 273 | 21 | ▶ | $entry->{size}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 274 | 21 | my $start = time; | |||||||||||||||||||||||||||||||||
| 275 | 21 | my $dest = $ftp->get( $entry->{name}, $destname ); | |||||||||||||||||||||||||||||||||
| 276 | 21 | my $t_time = time - $start; | |||||||||||||||||||||||||||||||||
| 277 | 21 | ▶ | $dest or $mirror_ok = 0, return; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||
| 279 | 19 | ▶ | $t_time or $t_time = 0.001; # avoid div by zero | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 280 | 19 | my $size = -s $dest; | |||||||||||||||||||||||||||||||||
| 281 | 19 | $totsize += $size; | |||||||||||||||||||||||||||||||||
| 282 | 19 | $tottime += $t_time; | |||||||||||||||||||||||||||||||||
| 283 | 19 | my $speed = $size / $t_time; | |||||||||||||||||||||||||||||||||
| 284 | 19 | my $ord = 0; | |||||||||||||||||||||||||||||||||
| 285 | 19 | ▶ | while ( $speed > 1024 ) { $speed /= 1024; $ord++ } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 286 | 19 | ▶ | my $dig = $ord ? '3' : '0'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||
| 288 | 19 | utime $entry->{time}, $entry->{time}, $dest; | |||||||||||||||||||||||||||||||||
| 289 | 19 | chmod $entry->{mode}, $dest; | |||||||||||||||||||||||||||||||||
| 290 | 19 | ▶ | $verbose and printf "$size (%.${dig}f $sn[$ord]/s)\n", | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 291 | $speed; | ||||||||||||||||||||||||||||||||||
| 292 | } else { | ||||||||||||||||||||||||||||||||||
| 293 | $verbose > 1 and | ||||||||||||||||||||||||||||||||||
| 294 | printf "%s: %d/skipped\n", abs2rel( $destname, $lroot), | ||||||||||||||||||||||||||||||||||
| 295 | 19 | ▶ | $entry->{size}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||
| 299 | 32 | ▶ | if ( $cleanup ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 300 | 32 | chdir $localdir; | |||||||||||||||||||||||||||||||||
| 301 | 32 | ▶ | $verbose > 1 and print "Cleanup '$localdir'\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 302 | my %ok_file = map { | ||||||||||||||||||||||||||||||||||
| 303 | 32 | ( clean_filename( $_->{name} ) => $_->{type} ) | |||||||||||||||||||||||||||||||||
| 304 | 132 | } @list; | |||||||||||||||||||||||||||||||||
| 305 | 32 | local *DIR; | |||||||||||||||||||||||||||||||||
| 306 | 32 | ▶ | if ( opendir DIR, '.' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 307 | 32 | foreach ( readdir DIR ) { | |||||||||||||||||||||||||||||||||
| 308 | 133 | my $cmpname = clean_filename( $_ ); | |||||||||||||||||||||||||||||||||
| 309 | 133 | ▶ | $^O eq 'VMS' and $cmpname =~ s/\.$//; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 310 | 133 | ▶ | if( -f $cmpname ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 311 | 39 | ▶ | unless ( exists $ok_file{ $cmpname } && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $ok_file{$cmpname} and $ok_file{$cmpname} eq "f"
MC/DC50%1/2
exists $ok_file{$cmpname} and $ok_file{$cmpname} eq "f"
exists $ok_file{$cmpname}
$ok_file{$cmpname} eq "f"
Truth table66%2/3
A and B
A= exists $ok_file{$cmpname}B= $ok_file{$cmpname} eq "f"
| |||||||||||||||||||||||||||||||||||
| 312 | $ok_file{ $cmpname } eq 'f' ) { | ||||||||||||||||||||||||||||||||||
| 313 | 1 | ▶ | $verbose and printf "Delete %s\n", | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 314 | abs2rel( rel2abs( $cmpname ), | ||||||||||||||||||||||||||||||||||
| 315 | $lroot ); | ||||||||||||||||||||||||||||||||||
| 316 | 1 | ▶ | 1 while unlink $_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||
| 318 | ▶ | } elsif ( -d && ! /^..?\z/ ) { | |||||||||||||||||||||||||||||||||
|
Condition66%2/3
-d $_ and not /^..?\z/
MC/DC50%1/2
-d $_ and not /^..?\z/
-d $_
not /^..?\z/
Truth table66%2/3
A and not(B)
A= -d $_B= not /^..?\z/
| |||||||||||||||||||||||||||||||||||
| 319 | 18 | ▶ | $^O eq 'VMS' and $cmpname =~ s/\.DIR$//i; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 320 | 18 | ▶ | unless ( exists $ok_file{ $cmpname } && | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $ok_file{$cmpname} and $ok_file{$cmpname} eq "d"
MC/DC0%0/2
exists $ok_file{$cmpname} and $ok_file{$cmpname} eq "d"
exists $ok_file{$cmpname}
$ok_file{$cmpname} eq "d"
Truth table33%1/3
A and B
A= exists $ok_file{$cmpname}B= $ok_file{$cmpname} eq "d"
| |||||||||||||||||||||||||||||||||||
| 321 | $ok_file{ $cmpname } eq 'd' ) { | ||||||||||||||||||||||||||||||||||
| 322 | 0 | rmtree( $cmpname, $verbose ); | |||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||
| 326 | 32 | closedir DIR; | |||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||
| 329 | 32 | @_[ -2, -1 ] = ( $totsize, $tottime ); | |||||||||||||||||||||||||||||||||
| 330 | 32 | return $mirror_ok; | |||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||
| 334 | =head2 dirlist( $ftp, $verbose ) | ||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||
| 336 | Return a list of entries (hashrefs) with these properties: | ||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||
| 338 | * name: Filename | ||||||||||||||||||||||||||||||||||
| 339 | * type f/d/l | ||||||||||||||||||||||||||||||||||
| 340 | * mode unix file mode | ||||||||||||||||||||||||||||||||||
| 341 | * size filessize in bytes | ||||||||||||||||||||||||||||||||||
| 342 | * date file date | ||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||
| 344 | =cut | ||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||
| 346 | 1 | ▶ | sub dirlist { | ||||||||||||||||||||||||||||||||
|
Subroutine
dirlist: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 347 | 34 | my( $ftp, $verbose ) = @_; | |||||||||||||||||||||||||||||||||
| 348 | 34 | map __parse_line_from_dir( $_, $verbose ) => $ftp->dir; | |||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||
| 351 | =head2 __parse_line_from_dir( $line, $verbose ) | ||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||
| 353 | The C<dir> command in FTP gives a sort of C<ls -la> output, | ||||||||||||||||||||||||||||||||||
| 354 | parts of this output are used as remote file-info. | ||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||
| 356 | =cut | ||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||
| 358 | 149 | ▶ | sub __parse_line_from_dir { | ||||||||||||||||||||||||||||||||
|
Subroutine
__parse_line_from_dir: called CC=3 SCAR=13.5
| |||||||||||||||||||||||||||||||||||
| 359 | 149 | my( $entry, $verbose ) = @_; | |||||||||||||||||||||||||||||||||
| 360 | 149 | my @field = split " ", $entry; | |||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||
| 362 | 149 | ▶ | if ( $field[0] =~ /[dwrx-]{7}/ ) { # Unixy dir entry | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||
| 364 | 149 | ( my $type = substr $field[0], 0, 1 ) =~ tr/-/f/; | |||||||||||||||||||||||||||||||||
| 365 | return { | ||||||||||||||||||||||||||||||||||
| 366 | 149 | name => $field[-1], | |||||||||||||||||||||||||||||||||
| 367 | type => $type, | ||||||||||||||||||||||||||||||||||
| 368 | mode => __get_mode_from_text( substr $field[0], 1 ), | ||||||||||||||||||||||||||||||||||
| 369 | size => $field[4], | ||||||||||||||||||||||||||||||||||
| 370 | time => 0, | ||||||||||||||||||||||||||||||||||
| 371 | date => __time_from_ls( @field[5, 6, 7] ), | ||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||
| 373 | } else { # Windowsy dir entry | ||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | my $type = $field[2] eq '<DIR>' ? 'd' : 'f'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 375 | return { | ||||||||||||||||||||||||||||||||||
| 376 | 0 | name => $field[-1], | |||||||||||||||||||||||||||||||||
| 377 | type => $type, | ||||||||||||||||||||||||||||||||||
| 378 | mode => 0777, | ||||||||||||||||||||||||||||||||||
| 379 | size => $field[2], | ||||||||||||||||||||||||||||||||||
| 380 | time => 0, | ||||||||||||||||||||||||||||||||||
| 381 | date => __time_from_windows( @field[0, 1] ), | ||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||
| 386 | =head2 __get_mode_from_text( $tmode ) | ||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||
| 388 | This takes the text representation of a file-mode (like 'rwxr--r--') | ||||||||||||||||||||||||||||||||||
| 389 | and return the numeric value. | ||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||
| 391 | =cut | ||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||
| 393 | 149 | ▶ | sub __get_mode_from_text { | ||||||||||||||||||||||||||||||||
|
Subroutine
__get_mode_from_text: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 394 | 149 | my( $tmode ) = @_; # nine letter/dash | |||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||
| 396 | 149 | $tmode =~ tr/rwx-/1110/; | |||||||||||||||||||||||||||||||||
| 397 | 149 | my $mode = 0; | |||||||||||||||||||||||||||||||||
| 398 | 149 | ▶ | for ( my $i = 0; $i < 3; $i++ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 399 | 447 | $mode <<= 3; | |||||||||||||||||||||||||||||||||
| 400 | 447 | $mode += ord(pack B3 => substr $tmode, $i*3, 3) >> 5; | |||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||
| 403 | 149 | return $mode; | |||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||
| 406 | =head2 __time_from_ls( $mname, $day, $time_or_year ) | ||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||
| 408 | This takes the three date/time related columns from the C<ls -la> output | ||||||||||||||||||||||||||||||||||
| 409 | and returns a localtime-stamp. | ||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||
| 411 | =cut | ||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||
| 413 | 149 | ▶ | sub __time_from_ls { | ||||||||||||||||||||||||||||||||
|
Subroutine
__time_from_ls: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 414 | 149 | my( $mname, $day, $time_or_year ) = @_; | |||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||
| 416 | 149 | my( $local_year, $local_month) = (localtime)[5, 4]; | |||||||||||||||||||||||||||||||||
| 417 | 149 | $local_year += 1900; | |||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||
| 419 | 149 | my $month = int( index('JanFebMarAprMayJunJulAugSepOctNovDec', $mname)/3 ); | |||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||
| 421 | 149 | ▶ | my( $year, $time ) = $time_or_year =~ /:/ | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 422 | ? $month > $local_month ? ( $local_year - 1, $time_or_year ) : | ||||||||||||||||||||||||||||||||||
| 423 | ($local_year, $time_or_year) : ($time_or_year, '00:00' ); | ||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||
| 425 | 149 | my( $hour, $minutes ) = $time =~ /(\d+):(\d+)/; | |||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||
| 427 | 149 | require Time::Local; | |||||||||||||||||||||||||||||||||
| 428 | 149 | return Time::Local::timelocal( 0, $minutes, $hour, $day, $month, $year ); | |||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||
| 431 | =head2 __time_from_windows( $date, $time ) | ||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||
| 433 | This takes the two date/time related columns from the C<dir> output | ||||||||||||||||||||||||||||||||||
| 434 | and returns a localtime-stamp | ||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||
| 436 | =cut | ||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | sub __time_from_windows { | ||||||||||||||||||||||||||||||||
|
Subroutine
__time_from_windows: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 439 | 0 | my( $date, $time ) = @_; | |||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||
| 441 | 0 | my( $day, $month, $year ) = split m/-/, $date; | |||||||||||||||||||||||||||||||||
| 442 | 0 | $month--; | |||||||||||||||||||||||||||||||||
| 443 | 0 | my( $hour, $minutes, $off ) = $time =~ m/(\d+):(\d+)([ap])m/i; | |||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | $off && lc $off eq 'p' and $hour += 12; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$off and lc $off eq "p"
MC/DC0%0/2
$off and lc $off eq "p"
$off
lc $off eq "p"
Truth table0%0/3
A and B
A= $offB= lc $off eq "p"
| |||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||
| 446 | 0 | require Time::Local; | |||||||||||||||||||||||||||||||||
| 447 | 0 | return Time::Local::timelocal( 0, $minutes, $hour, $day, $month, $year ); | |||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||
| 450 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||
| 452 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||
| 454 | L<Test::Smoke::Syncer> | ||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||
| 456 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||
| 458 | (c) 2003, 2004, 2005, Abe Timmerman <abeltje@cpan.org> All rights reserved. | ||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||
| 460 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||
| 461 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||
| 463 | See: | ||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||
| 465 | * <http://www.perl.com/perl/misc/Artistic.html>, | ||||||||||||||||||||||||||||||||||
| 466 | * <http://www.gnu.org/copyleft/gpl.html> | ||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||
| 468 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||
| 469 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||
| 470 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||
| 472 | =cut | ||||||||||||||||||||||||||||||||||