| 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
MC/DC0%0/1
$self->{'FOLLOW_SYMLINK'} || undef
$self->{'FOLLOW_SYMLINK'}
Truth table50%1/2
A
A= $self->{'FOLLOW_SYMLINK'}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | 156 | ▶ | next if( $dir_entry =~ /^\.{1,2}$/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
not $self->{"FOLLOW_SYMLINK"} and -l $filename
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
| |||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | 0 | next; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 100 | ▶ | if( -d $filename ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||