Treemap/Input/Dir.pm

filter: Statementstmt 91.4% 64 / 70 Branchbran 81.2% 13 / 16 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 90.9% 10 / 11 Podpod 100% 2 / 2 totaltotal 85.0% 91 / 107 CC 11 SCAR 14.1
CC
11
Cov
87%
_load
8.2
load
2.1
_init
2.1
CRAP 4.1
« Treemap/Strip.pm ↑ Summary Treemap/Input/Cache.pm »
1 package Treemap::Input::Dir;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 require Exporter;
11 1 require Treemap::Input;
12  
13 1 our @ISA = qw( Treemap::Input Exporter );
14 1 our @EXPORT_OK = ( );
15 1 our @EXPORT = qw( );
16 1 our $VERSION = '0.01';
17  
18 # ------------------------------------------
19 # Methods:
20 # ------------------------------------------
21 sub new
22 1 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
23 1 my $classname = shift;
24 1 my $self = $classname->SUPER::new( @_ ); # Call parent constructor
25 1 $self->_init( @_ ); # Initialize child variables
26 1 return $self;
27 }
28  
29 sub _init
30 1 ▶{
Subroutine _init: called CC=2 SCAR=7.2
31 1 my $self = shift;
32 1 ▶ $self->{FOLLOW_SYMLINK} = $self->{FOLLOW_SYMLINK} || undef;
Condition50%1/2
$self->{'FOLLOW_SYMLINK'} || undef
l!l
01
MC/DC0%0/1
$self->{'FOLLOW_SYMLINK'} || undef
$self->{'FOLLOW_SYMLINK'}
Truth table50%1/2
A
A= $self->{'FOLLOW_SYMLINK'}
Aresult
11
00
33 }
34  
35 sub load
36 1 ▶{
Subroutine load: called CC=2 SCAR=7.4
Pod documented
37 1 my $self = shift;
38 1 my( $path ) = @_;
39  
40 1 ▶ if ( $self->{ DATA } = $self->_load( $path ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DATA"} = $self->_load($path)) 1 0 1
41 {
42 1 return 1;
43 }
44 0 return 0;
45 }
46  
47 # ------------------------------------------
48 # _load()
49 # ------------------------------------------
50 sub _load
51 28 ▶{
Subroutine _load: called CC=8 SCAR=21.0
52 28 my $self = shift;
53 28 my( $path ) = @_;
54 28 my( $tree, $DH, @children, $size );
55  
56 28 @children = ();
57 28 $size = 0;
58  
59 28 opendir( $DH, $path );
60  
61 28 ▶ while( my $dir_entry = readdir( $DH ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $dir_entry = readdir $DH)) 156 28 184
62 {
63 156 ▶ next if( $dir_entry =~ /^\.{1,2}$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $dir_entry =~ /^\.{1,2}$/ 56 100 156
64  
65 100 my $item;
66 100 my $filename = "$path/$dir_entry";
67  
68 # Skip Sympbolic Links
69 100 ▶ if( !$self->{FOLLOW_SYMLINK} && -l $filename )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"FOLLOW_SYMLINK"} and -l $filename) 0 100 100
Condition33%1/3
not $self->{"FOLLOW_SYMLINK"} and -l $filename
!ll&&!rl&&r
01000
MC/DC0%0/2
not $self->{"FOLLOW_SYMLINK"} and -l $filename
not $self->{"FOLLOW_SYMLINK"} -l $filename
Truth table33%1/3
not(A) and B
A= not $self->{"FOLLOW_SYMLINK"}B= -l $filename
ABresult
0X0
100
111
70 {
71 0 next;
72 }
73  
74 100 ▶ if( -d $filename )
Branch: 2 branches
BranchTrueFalseTotal
if (-d $filename) { } 27 73 100
elsif (-f $filename) { } 73 0 73
75 {
76 27 $item = $self->_load( $filename );
77 27 $item->{name} = basename( $item->{name} );
78 }
79 elsif( -f $filename )
80 {
81 73 ( $item->{size}, my $mtime ) = (stat( $filename ))[7,9];
82 73 $item->{name} = $dir_entry;
83  
84 73 $item->{colour} = $self->_colour_by_mtime( $mtime );
85 }
86 else
87 {
88 0 next;
89 }
90 100 push( @children, $item );
91 100 $size += $item->{size};
92 }
93 28 close( $DH );
94
95 28 $tree->{name} = $path;
96 28 $tree->{size} = $size;
97 28 $tree->{colour} = "#FFFFFF";
98 28 ▶ $tree->{children} = \@children if( scalar(@children) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @children > 0 27 1 28
99  
100 28 return $tree;
101 }
102  
103 sub _colour_by_mtime
104 73 ▶{
Subroutine _colour_by_mtime: called CC=2 SCAR=6.9
105 73 my $self = shift;
106 73 my $mtime = shift;
107 73 my $ctime = time;
108  
109 73 my $age = 1 + ( $ctime - $mtime ) / ( 60 * 60 );
110 73 my $level = int ( log( $age ) * 10 );
111  
112 73 ▶ $level = 100 if ( $level > 100 );
Branch: 1 branch
BranchTrueFalseTotal
if $level > 100 55 18 73
113  
114 73 $level = int( 255 * ( $level / 100 ));
115
116 73 return sprintf("#%02X%02X%02X", 255-$level, 0, $level );
117 }
118  
119 sub _colour_by_type
120 0 ▶{
Subroutine _colour_by_type: not called CC=1 SCAR=6.9
121 0 my $self = shift;
122 0 my $ext = shift;
123  
124 0 $ext =~ m/(\w)(\w)?(\w)?/;
125 }
126  
127 1 1;
128  
129 __END__
« Treemap/Strip.pm ↑ Summary Treemap/Input/Cache.pm »