Feed/Source/file.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 93 CC 6 SCAR 15.2
CC
6
Cov
0%
list
12.0
begin
6.0
_crawl
6.0
CRAP 4.6
1 package File::Feed::Source::file;
2  
3 use strict;
4 use warnings;
5  
6 use vars qw(@ISA);
7  
8 @ISA = qw(File::Feed::Source);
9  
10 use File::Feed::Source;
11 use File::Feed::File;
12 use File::Copy qw(copy move);
13  
14 sub protocol { 'file' }
15  
16 sub feed { $_[0]->{'_feed'} }
17 sub destination { $_[0]->{'destination'} }
18  
19 sub begin {
20 my ($self, $feed) = @_;
21 my $root = $self->root;
22 die "No such directory: $root" if !-d $root;
23 return $self;
24 }
25  
26 sub end { }
27  
28 sub id { $_[0]->{'#'} }
29  
30 sub list {
31 my ($self, $path, $recursive) = @_;
32 my $root = $self->root;
33 my $abspath = defined $path ? "$root/$path" : $root;
34 my $ofs = length($abspath) + 1;
35 my @files;
36 if ($recursive) {
37 _crawl($abspath, \@files);
38 }
39 else {
40 @files = fgrep { -f $_ } glob("$abspath/*");
41 }
42 return map { substr($_, $ofs) } @files;
43 }
44  
45 sub _crawl {
46 my ($path, $list) = @_;
47 my @files = glob("$path/*");
48 foreach (@files) {
49 if (-d $_) {
50 _crawl($path, $list);
51 }
52 else {
53 push @$list, $_;
54 }
55 }
56 }
57  
58 sub fetch_file {
59 my ($self, $from, $to) = @_;
60 if ($self->{'copy'}) {
61 copy($from, $to) or die "Can't fetch $from: $!";
62 }
63 else {
64 move($from, $to) or die "Can't fetch $from: $!";
65 }
66 }
67  
68 sub basename {
69 (my $path = shift) =~ s{^.+/}{};
70 return $path;
71 }
72  
73 1;
74  
75 =pod
76  
77 =head1 NAME
78  
79 File::Feed::Source::file - fetch files from a filesystem
80  
81 =cut
82