PS1/Plugin/Directory.pm

filter: Statementstmt 29.4% 20 / 68 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 20.9% 27 / 129 CC 23 SCAR 60.8
CC
23
Cov
18%
directory
552.0
BEGIN
1.0
BEGIN
1.0
CRAP 438.0
↑ Summary PS1/Plugin/Branch.pm »
1 package App::PS1::Plugin::Directory;
2  
3 # Created on: 2011-06-21 09:48:32
4 # Create by: Ivan Wills
5 # $Id$
6 # $Revision$, $HeadURL$, $Date$
7 # $Revision$, $Source$, $Date$
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Data::Dumper qw/Dumper/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our $VERSION = 0.08;
17  
18 0 ▶sub directory {
Subroutine directory: not called CC=23 SCAR=63.1
Pod documented
19 0 my ($self, $options) = @_;
20  
21 0 my $dir = path('.')->absolute;
22 0 my $home = path($ENV{HOME});
23 0 my $dir_display = "$dir";
24 0 ▶ $options->{dir_length} ||= 30;
Condition0%0/2
$options->{"dir_length"} ||= 30
l!l
00
MC/DC0%0/1
$options->{"dir_length"} ||= 30
$options->{"dir_length"}
Truth table0%0/2
A
A= $options->{"dir_length"}
Aresult
11
00
25  
26 0 ▶ if ($home->subsumes($dir) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($home->subsumes($dir)) 0 0 0
27 0 $dir_display =~ s/$home/~/xms;
28 }
29 0 ▶ if (length $dir_display > $options->{dir_length}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $dir_display > $options->{"dir_length"}) 0 0 0
30 0 $dir_display = '...' . substr $dir_display, -$options->{dir_length}, $options->{dir_length};
31 }
32 0 ▶ if ($options->{abreviate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"abreviate"}) 0 0 0
33 0 $dir_display =~ s{/([^/])[^/]+/}{/$1/}g;
34 }
35  
36 0 my $len = length $dir_display;
37  
38 0 my @details = ( $len, $self->colour('dir_name') . $dir_display );
39  
40 0 my @children = $dir->children;
41 0 my $dir_count = 0;
42 0 my $file_count = 0;
43 0 my $size = 0;
44 0 for my $file (@children) {
45 0 ▶ if ( -d $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file) { } 0 0 0
46 0 $dir_count++;
47 }
48 else {
49 0 $file_count++;
50 0 ▶ $size += -s $file || 0;
Condition0%0/2
-s $file || 0
l!l
00
MC/DC0%0/1
-s $file || 0
-s $file
Truth table0%0/2
A
A= -s $file
Aresult
11
00
51 }
52 }
53 $size
54 0 ▶ = $size > 10_000_000_000 ? sprintf "%dGiB" , $size / 2**30
Branch: 6 branches
BranchTrueFalseTotal
$size > 10000000000 ? : 0 0 0
$size > 900000000 ? : 0 0 0
$size > 10000000 ? : 0 0 0
$size > 900000 ? : 0 0 0
$size > 10000 ? : 0 0 0
$size > 900 ? : 0 0 0
55 : $size > 900_000_000 ? sprintf "%.1dGiB", $size / 2**30
56 : $size > 10_000_000 ? sprintf "%dMiB" , $size / 2**20
57 : $size > 900_000 ? sprintf "%.1dMiB", $size / 2**20
58 : $size > 10_000 ? sprintf "%dKiB" , $size / 2**10
59 : $size > 900 ? sprintf "%.1dKiB", $size / 2**10
60 : $size;
61  
62 0 my $dir_length = 0;
63 0 my $file_length = 0;
64 0 my $size_length = 0;
65  
66 0 ▶ if (!defined $options->{dir} || $options->{dir}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $options->{'dir'} or $options->{'dir'}) { } 0 0 0
Condition0%0/3
not defined $options->{"dir"} or $options->{"dir"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $options->{"dir"} or $options->{"dir"}
not defined $options->{"dir"} $options->{"dir"}
Truth table0%0/3
not(A) or B
A= not defined $options->{"dir"}B= $options->{"dir"}
ABresult
1X1
011
000
67 0 $dir_length = 6 + length $dir_count;
68 0 $dir_count = $self->colour('dir_label') . " dir:" . $self->colour('dir_size') . "$dir_count,";
69 }
70 else {
71 0 $dir_count = '';
72 }
73 0 ▶ if (!defined $options->{file} || $options->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $options->{'file'} or $options->{'file'}) { } 0 0 0
Condition0%0/3
not defined $options->{"file"} or $options->{"file"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $options->{"file"} or $options->{"file"}
not defined $options->{"file"} $options->{"file"}
Truth table0%0/3
not(A) or B
A= not defined $options->{"file"}B= $options->{"file"}
ABresult
1X1
011
000
74 0 $file_length = 7 + length $file_count;
75 0 $file_count = $self->colour('dir_label') . " file:" . $self->colour('dir_size') . "$file_count,";
76 }
77 else {
78 0 $file_count = '';
79 }
80 0 ▶ if (!defined $options->{size} || $options->{size}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $options->{'size'} or $options->{'size'}) { } 0 0 0
Condition0%0/3
not defined $options->{"size"} or $options->{"size"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $options->{"size"} or $options->{"size"}
not defined $options->{"size"} $options->{"size"}
Truth table0%0/3
not(A) or B
A= not defined $options->{"size"}B= $options->{"size"}
ABresult
1X1
011
000
81 0 $size_length = 1 + length $size;
82 0 $size = $self->colour('dir_label') . " " . $self->colour('dir_size') . $size;
83 }
84 else {
85 0 $size = '';
86 }
87  
88 0 my $arb = @{$self->parts} + $self->parts_size;
89 0 ▶ if ( $details[0] + $dir_length + $file_length + $size_length + $arb < $self->cols ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($details[0] + $dir_length + $file_length + $size_length + $arb < $self->cols) { } 0 0 0
elsif ($details[0] + $file_length + $size_length + $arb < $self->cols) { } 0 0 0
elsif ($details[0] + $size_length + $arb - 5 < $self->cols) { } 0 0 0
90 0 $details[0] += $dir_length + $file_length + $size_length;
91 0 $details[1] .= $dir_count . $file_count . $size;
92 }
93 elsif ( $details[0] + $file_length + $size_length + $arb < $self->cols ) {
94 0 $details[0] += $file_length + $size_length;
95 0 $details[1] .= $file_count . $size;
96 }
97 elsif ( $details[0] + $size_length + $arb - 5 < $self->cols ) {
98 0 $details[0] += $size_length;
99 0 $details[1] .= $size;
100 }
101  
102 0 return $self->surround(@details);
103 }
104  
105 1 1;
106  
107 __END__
↑ Summary PS1/Plugin/Branch.pm »