FTPTurboSync.pm

filter: Statementstmt 47.6% 41 / 86 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.7% 11 / 17 Podpod 60.0% 3 / 5 totaltotal 42.9% 55 / 128 CC 16 SCAR 33.9
CC
16
Cov
39%
noticelocalfile
90.0
buildlocaltree
13.8
buildremotetree
12.0
CRAP 29.8
« FTPTurboSync/MyFtp.pm ↑ Summary FTPTurboSync/RemoteFile.pm »
1 # Copyright (c) 2011 Daneel S. Yaitskov <rtfm.rtfm.rtfm@gmail.com.>.
2  
3 # All rights reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the same terms as Perl itself.
6  
7 package Net::FTPTurboSync;
8  
9 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Net::FTPTurboSync::PrgOpts;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Net::FTPTurboSync::LocalFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Net::FTPTurboSync::LocalDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Net::FTPTurboSync::RemoteDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Net::FTPTurboSync::RemoteFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 require Exporter;
20  
21 1 our @ISA = qw(Exporter);
22  
23 # Items to export into callers namespace by default. Note: do not export
24 # names by default without a very good reason. Use EXPORT_OK instead.
25 # Do not simply export all your public functions/methods/constants.
26  
27 # This allows declaration use Net::FTPTurboSync ':all';
28 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
29 # will save memory.
30 1 our %EXPORT_TAGS = ( 'all' => [ qw() ] );
31  
32 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
33  
34 1 our @EXPORT = qw();
35  
36 1 our $VERSION = '0.07';
37  
38 0 ▶sub theOpts {
Subroutine theOpts: not called CC=1 SCAR=6.9
Pod undocumented
39 0 return $Net::FTPTurboSync::PrgOpts::theOpts;
40 }
41  
42 1 my $theOpts = $Net::FTPTurboSync::PrgOpts::theOpts;
43  
44 =head1 NAME
45  
46 Net::FTPTurboSync - Perl extension for turbo-ftp-sync script
47  
48 =head1 SYNOPSIS
49  
50 =head1 DESCRIPTION
51  
52 Blah blah blah.
53  
54 =head2 EXPORT
55  
56 None by default.
57  
58 =over
59  
60 =item B<buildlocaltree>()
61  
62 class - name of this module
63  
64 It build two hashes of all directories and all files including nested and
65 returns an array of hash references to them, respectively. Hashes' key is a
66 relative path to file or folder from current folder.
67  
68 =cut
69  
70 0 ▶sub buildlocaltree () {
Subroutine buildlocaltree: not called CC=4 SCAR=26.3
Pod documented
71 0 my ($class) = @_;
72 0 my %ldirs = ();
73 0 my %lfiles = ();
74 0 chdir theOpts()->{localdir};
75 0 my $ldl = length(Cwd::getcwd());
76 0 ▶ if ($theOpts->{doflat}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($theOpts->{'doflat'}) { } 0 0 0
77 0 ▶ my @globbed=glob("{*,.*}");
Subroutine BEGIN: called CC=1 SCAR=0.2
78 0 foreach my $curglobbed (@globbed) {
79 0 ▶ next if (! -f $curglobbed);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $curglobbed 0 0 0
80 0 $lfiles{$curglobbed} = Net::FTPTurboSync::LocalFile->load ( $curglobbed );
81 }
82 } else {
83 0 ▶ find ( { wanted=> sub { noticelocalfile ( $File::Find::name,
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 \%ldirs,
85 \%lfiles, $ldl ) ; },
86 follow_fast => $theOpts->{followsymlinks},
87 0 no_chdir => 1
88 },
89
90 Cwd::getcwd()."/"
91 );
92 }
93 0 return ( \%ldirs, \%lfiles );
94
95 0 ▶ sub noticelocalfile {
Subroutine noticelocalfile: not called CC=9 SCAR=45.0
Pod undocumented
96 0 my ( $fileName, $ldirs, $lfiles, $ldl ) = @_;
97 0 my $relfilename = substr( $fileName, $ldl );
98 0 $relfilename =~ s!^/!!;
99 0 ▶ if (length($relfilename) == 0) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if (length $relfilename == 0) 0 0 0
100 0 my $theOpts = theOpts();
101 0 ▶ if (theOpts()->{ignoremask} ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if (theOpts()->{"ignoremask"} ne "") 0 0 0
102 0 ▶ if ($relfilename =~ /$theOpts->{ignoremask}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relfilename =~ /$theOpts->{"ignoremask"}/) 0 0 0
103 0 ▶ if ($theOpts->{doverbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($theOpts->{"doverbose"}) 0 0 0
104 0 print "Ignoring $relfilename which matches $theOpts->{ignoremask}\n";
105 }
106 0 return;
107 }
108 }
109 0 ▶ if (-d $_) {
Branch: 4 branches
BranchTrueFalseTotal
if (-d $_) { } 0 0 0
elsif (-f $_) { } 0 0 0
elsif (-l $_) { } 0 0 0
elsif (not $theOpts->{'doquiet'}) { } 0 0 0
110 0 $ldirs->{$relfilename} = Net::FTPTurboSync::LocalDir->load ( $relfilename );
111 }elsif (-f $_) {
112 0 $lfiles->{$relfilename} = Net::FTPTurboSync::LocalFile->load ( $relfilename );
113 }elsif (-l $_) {
114 0 print "Link isn't supported: $fileName\n";
115 }elsif (! $theOpts->{doquiet}) {
116 0 print "Ignoring file of unknown type: $fileName\n";
117 }
118 }
119 }
120  
121 =item B<buildremotetree>($ftp,$dbh)
122  
123 class - name of this module
124  
125 ftp - object Net::FTPTurboSync::MyFtp
126  
127 dbh - database handle which is returned from DBI->connect(...)
128  
129 The method returns an array with two elements. First is a hash ref of
130 directories found in current folder on FTP server. Second is a hash ref o files
131 found in current folder on FTP server. A hask key of both hashes is an absolute
132 path. A hash value of first hash is RemoteDir object and a second one is
133 RemoteFile object.
134  
135 The method gets data from the database object rather than ftp. Ftp object is
136 passed for futher using.
137 =cut
138  
139 0 ▶sub buildremotetree() {
Subroutine buildremotetree: not called CC=3 SCAR=24.8
Pod documented
140 0 my ( $class, $ftp, $dbh ) = @_;
141 0 my %rdirs = ();
142 0 my %rfiles = ();
143 0 my $dirs = $dbh->selectAllDirs();
144 0 foreach my $dir ( @$dirs ){
145 0 $rdirs{ $dir->{fullname} } = Net::FTPTurboSync::RemoteDir->load ( $ftp, $dbh, $dir ) ;
146 }
147 0 my $files = $dbh->selectAllFiles();
148 0 foreach my $file ( @$files ){
149 0 $rfiles{ $file->{fullname} } = Net::FTPTurboSync::RemoteFile->load( $ftp, $dbh, $file );
150 }
151 0 return ( \%rdirs, \%rfiles );
152 }
153  
154 =item B<fillDb>($dbh,$ldir,$lfiles)
155  
156 class - name of this module
157  
158 dbh - database handle object
159  
160 ldir - a hash ref of directories to be written in db
161
162 lfiles - a hash ref of files to be written in db
163  
164 =cut
165  
166 0 ▶sub fillDb {
Subroutine fillDb: not called CC=3 SCAR=24.8
Pod documented
167 0 my ($class, $dbh, $ldirs, $lfiles) = @_;
168 0 foreach my $lfile (values(%$lfiles)) {
169 0 $dbh->uploadFile( $lfile->getPath,
170 $lfile->getPerms,
171 $lfile->getModDate,
172 $lfile->getSize );
173 }
174 0 foreach my $ldir ( values ( %$ldirs ) ) {
175 0 $dbh->createDir( $ldir->getPath, $ldir->getPerms );
176 }
177 }
178  
179 1 1;
180 __END__
« FTPTurboSync/MyFtp.pm ↑ Summary FTPTurboSync/RemoteFile.pm »