Visitor/CreateDirectoryTree.pm

filter: Statementstmt 100% 51 / 51 Branchbran 85.7% 12 / 14 Conditioncond 86.6% 13 / 15 MC/DCmcdc 80.0% 8 / 10 Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 94.3% 101 / 107 CC 14 SCAR 9.9
CC
14
Cov
95%
_createDirectoryStructure
5.0
visit
3.0
setFileHandler
3.0
CRAP 2.7
« Visitor/PostOrderTraversal.pm ↑ Summary Visitor/Sort.pm »
1 package Tree::Simple::Visitor::CreateDirectoryTree;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.16';
7  
8 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use base qw(Tree::Simple::Visitor);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
14 3 my ($_class) = @_;
15 3 ▶ my $class = ref($_class) || $_class;
Condition33%1/3
ref $_class || $_class
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $_class || $_class
ref $_class $_class
Truth table33%1/3
A || B
A= ref $_classB= $_class
ABresult
1X1
011
000
16 3 my $visitor = {};
17 3 bless($visitor, $class);
18 3 $visitor->_init();
19 3 return $visitor;
20 }
21  
22 3 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
23 3 my ($self) = @_;
24 3 ▶ $self->{file_handler} = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
25 3 my ($filepath) = @_;
26 3 ▶ open(FILE, ">", $filepath) || die "IO Error : Cannot create file ($filepath) : $!";
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">", $filepath or die "IO Error : Cannot create file ($filepath) : $!" 3 0 3
27 3 close(FILE);
28 3 };
29 5 ▶ $self->{dir_handler} = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
30 5 my ($dirpath) = @_;
31 5 ▶ mkdir($dirpath) || die "IO Error : Cannot make directory ($dirpath) : $!";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $dirpath or die "IO Error : Cannot make directory ($dirpath) : $!" 5 0 5
32 3 };
33 3 $self->SUPER::_init();
34 }
35  
36 6 ▶sub visit {
Subroutine visit: called CC=3 SCAR=11.0
Pod documented
37 6 my ($self, $tree) = @_;
38 6 ▶ (blessed($tree) && $tree->isa("Tree::Simple"))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($tree) and $tree->isa("Tree::Simple") or die "Insufficient Arguments : You must supply a valid Tree::Simple object" 2 4 6
Condition100%3/3
builtin::blessed($tree) and $tree->isa("Tree::Simple")
!ll&&!rl&&r
312
MC/DC100%2/2
builtin::blessed($tree) and $tree->isa("Tree::Simple")
builtin::blessed($tree) $tree->isa("Tree::Simple")
Truth table100%3/3
A and B
A= builtin::blessed($tree)B= $tree->isa("Tree::Simple")
ABresult
0X0
100
111
39 || die "Insufficient Arguments : You must supply a valid Tree::Simple object";
40 # pass on to our recursive subroutine
41 2 $self->_createDirectoryStructure($tree);
42 }
43  
44 4 ▶sub setFileHandler {
Subroutine setFileHandler: called CC=3 SCAR=11.0
Pod documented
45 4 my ($self, $file_handler) = @_;
46 4 ▶ (defined($file_handler) && ref($file_handler) eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
defined $file_handler and ref $file_handler eq "CODE" or die "Insufficient Arguments : file handler must be a subroutine reference" 1 3 4
Condition100%3/3
defined $file_handler and ref $file_handler eq "CODE"
!ll&&!rl&&r
121
MC/DC100%2/2
defined $file_handler and ref $file_handler eq "CODE"
defined $file_handler ref $file_handler eq "CODE"
Truth table100%3/3
A and B
A= defined $file_handlerB= ref $file_handler eq "CODE"
ABresult
0X0
100
111
47 || die "Insufficient Arguments : file handler must be a subroutine reference";
48 1 $self->{file_handler} = $file_handler;
49 }
50  
51 4 ▶sub setDirectoryHandler {
Subroutine setDirectoryHandler: called CC=3 SCAR=11.0
Pod documented
52 4 my ($self, $dir_handler) = @_;
53 4 ▶ (defined($dir_handler) && ref($dir_handler) eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
defined $dir_handler and ref $dir_handler eq "CODE" or die "Insufficient Arguments : directory handler must be a subroutine reference" 1 3 4
Condition100%3/3
defined $dir_handler and ref $dir_handler eq "CODE"
!ll&&!rl&&r
121
MC/DC100%2/2
defined $dir_handler and ref $dir_handler eq "CODE"
defined $dir_handler ref $dir_handler eq "CODE"
Truth table100%3/3
A and B
A= defined $dir_handlerB= ref $dir_handler eq "CODE"
ABresult
0X0
100
111
54 || die "Insufficient Arguments : directory handler must be a subroutine reference";
55 1 $self->{dir_handler} = $dir_handler;
56 }
57  
58 16 ▶sub _createDirectoryStructure {
Subroutine _createDirectoryStructure: called CC=5 SCAR=16.1
59 16 my ($self, $tree, @path) = @_;
60 16 my $node = $tree->getNodeValue();
61 # filter the nodes if need be
62 16 my $filter_function = $self->getNodeFilter();
63 16 ▶ $node = $filter_function->($node) if $filter_function;
Branch: 1 branch
BranchTrueFalseTotal
if $filter_function 8 8 16
64 # if its a leaf and it
65 # doesn't end with a /
66 # then its a file
67 16 ▶ if ($tree->isLeaf() && $node !~ /\/|\\$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->isLeaf and not $node =~ m[/|\\$]) { } 6 10 16
Condition100%3/3
$tree->isLeaf and not $node =~ m[/|\\$]
!ll&&!rl&&r
646
MC/DC100%2/2
$tree->isLeaf and not $node =~ m[/|\\$]
$tree->isLeaf not $node =~ m[/|\\$]
Truth table100%3/3
A and not(B)
A= $tree->isLeafB= not $node =~ m[/|\\$]
ABresult
0X0
100
111
68 6 $self->{file_handler}->(File::Spec->catfile(@path, $node));
69 }
70 # otherwise we are going
71 # to treat it as a directory
72 else {
73 10 $node =~ s/\/|\\$//;
74 10 $self->{dir_handler}->(File::Spec->catdir(@path, $node));
75 10 foreach my $child ($tree->getAllChildren()) {
76 14 $self->_createDirectoryStructure($child, (@path, $node));
77 }
78 }
79 }
80  
81 1 1;
82  
83 __END__
« Visitor/PostOrderTraversal.pm ↑ Summary Visitor/Sort.pm »