| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Treemap::Input::Dir; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21229
|
use 5.006; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
35
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
31
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
31
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
126
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use File::Basename; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
790
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
|
11
|
|
|
|
|
|
|
require Treemap::Input; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw( Treemap::Input Exporter ); |
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = ( ); |
|
15
|
|
|
|
|
|
|
our @EXPORT = qw( ); |
|
16
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# ------------------------------------------ |
|
19
|
|
|
|
|
|
|
# Methods: |
|
20
|
|
|
|
|
|
|
# ------------------------------------------ |
|
21
|
|
|
|
|
|
|
sub new |
|
22
|
|
|
|
|
|
|
{ |
|
23
|
1
|
|
|
1
|
1
|
11
|
my $classname = shift; |
|
24
|
1
|
|
|
|
|
11
|
my $self = $classname->SUPER::new( @_ ); # Call parent constructor |
|
25
|
1
|
|
|
|
|
3
|
$self->_init( @_ ); # Initialize child variables |
|
26
|
1
|
|
|
|
|
2
|
return $self; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _init |
|
30
|
|
|
|
|
|
|
{ |
|
31
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
|
32
|
1
|
|
50
|
|
|
10
|
$self->{FOLLOW_SYMLINK} = $self->{FOLLOW_SYMLINK} || undef; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub load |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
1
|
|
|
1
|
1
|
549
|
my $self = shift; |
|
38
|
1
|
|
|
|
|
2
|
my( $path ) = @_; |
|
39
|
|
|
|
|
|
|
|
|
40
|
1
|
50
|
|
|
|
4
|
if ( $self->{ DATA } = $self->_load( $path ) ) |
|
41
|
|
|
|
|
|
|
{ |
|
42
|
1
|
|
|
|
|
11
|
return 1; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
0
|
|
|
|
|
0
|
return 0; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# ------------------------------------------ |
|
48
|
|
|
|
|
|
|
# _load() |
|
49
|
|
|
|
|
|
|
# ------------------------------------------ |
|
50
|
|
|
|
|
|
|
sub _load |
|
51
|
|
|
|
|
|
|
{ |
|
52
|
24
|
|
|
24
|
|
25
|
my $self = shift; |
|
53
|
24
|
|
|
|
|
31
|
my( $path ) = @_; |
|
54
|
24
|
|
|
|
|
21
|
my( $tree, $DH, @children, $size ); |
|
55
|
|
|
|
|
|
|
|
|
56
|
24
|
|
|
|
|
28
|
@children = (); |
|
57
|
24
|
|
|
|
|
21
|
$size = 0; |
|
58
|
|
|
|
|
|
|
|
|
59
|
24
|
|
|
|
|
512
|
opendir( $DH, $path ); |
|
60
|
|
|
|
|
|
|
|
|
61
|
24
|
|
|
|
|
257
|
while( my $dir_entry = readdir( $DH ) ) |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
138
|
100
|
|
|
|
452
|
next if( $dir_entry =~ /^\.{1,2}$/ ); |
|
64
|
|
|
|
|
|
|
|
|
65
|
90
|
|
|
|
|
67
|
my $item; |
|
66
|
90
|
|
|
|
|
126
|
my $filename = "$path/$dir_entry"; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Skip Sympbolic Links |
|
69
|
90
|
50
|
33
|
|
|
1307
|
if( !$self->{FOLLOW_SYMLINK} && -l $filename ) |
|
70
|
|
|
|
|
|
|
{ |
|
71
|
0
|
|
|
|
|
0
|
next; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
90
|
100
|
|
|
|
1462
|
if( -d $filename ) |
|
|
|
50
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
{ |
|
76
|
23
|
|
|
|
|
58
|
$item = $self->_load( $filename ); |
|
77
|
23
|
|
|
|
|
557
|
$item->{name} = basename( $item->{name} ); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
elsif( -f $filename ) |
|
80
|
|
|
|
|
|
|
{ |
|
81
|
67
|
|
|
|
|
778
|
( $item->{size}, my $mtime ) = (stat( $filename ))[7,9]; |
|
82
|
67
|
|
|
|
|
128
|
$item->{name} = $dir_entry; |
|
83
|
|
|
|
|
|
|
|
|
84
|
67
|
|
|
|
|
108
|
$item->{colour} = $self->_colour_by_mtime( $mtime ); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
else |
|
87
|
|
|
|
|
|
|
{ |
|
88
|
0
|
|
|
|
|
0
|
next; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
90
|
|
|
|
|
128
|
push( @children, $item ); |
|
91
|
90
|
|
|
|
|
302
|
$size += $item->{size}; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
24
|
|
|
|
|
27
|
close( $DH ); |
|
94
|
|
|
|
|
|
|
|
|
95
|
24
|
|
|
|
|
56
|
$tree->{name} = $path; |
|
96
|
24
|
|
|
|
|
30
|
$tree->{size} = $size; |
|
97
|
24
|
|
|
|
|
36
|
$tree->{colour} = "#FFFFFF"; |
|
98
|
24
|
100
|
|
|
|
59
|
$tree->{children} = \@children if( scalar(@children) > 0 ); |
|
99
|
|
|
|
|
|
|
|
|
100
|
24
|
|
|
|
|
260
|
return $tree; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _colour_by_mtime |
|
104
|
|
|
|
|
|
|
{ |
|
105
|
67
|
|
|
67
|
|
88
|
my $self = shift; |
|
106
|
67
|
|
|
|
|
63
|
my $mtime = shift; |
|
107
|
67
|
|
|
|
|
66
|
my $ctime = time; |
|
108
|
|
|
|
|
|
|
|
|
109
|
67
|
|
|
|
|
99
|
my $age = 1 + ( $ctime - $mtime ) / ( 60 * 60 ); |
|
110
|
67
|
|
|
|
|
98
|
my $level = int ( log( $age ) * 10 ); |
|
111
|
|
|
|
|
|
|
|
|
112
|
67
|
100
|
|
|
|
6893
|
$level = 100 if ( $level > 100 ); |
|
113
|
|
|
|
|
|
|
|
|
114
|
67
|
|
|
|
|
67
|
$level = int( 255 * ( $level / 100 )); |
|
115
|
|
|
|
|
|
|
|
|
116
|
67
|
|
|
|
|
241
|
return sprintf("#%02X%02X%02X", 255-$level, 0, $level ); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _colour_by_type |
|
120
|
|
|
|
|
|
|
{ |
|
121
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
122
|
0
|
|
|
|
|
|
my $ext = shift; |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
$ext =~ m/(\w)(\w)?(\w)?/; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |