| 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
MC/DC0%0/1
$options->{"dir_length"} ||= 30
$options->{"dir_length"}
Truth table0%0/2
A
A= $options->{"dir_length"}
| |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if ($home->subsumes($dir) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 27 | 0 | $dir_display =~ s/$home/~/xms; | |||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if (length $dir_display > $options->{dir_length}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 30 | 0 | $dir_display = '...' . substr $dir_display, -$options->{dir_length}, $options->{dir_length}; | |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ($options->{abreviate}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||
| 46 | 0 | $dir_count++; | |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||
| 48 | else { | ||||||||||||||||||||||||||||||
| 49 | 0 | $file_count++; | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $size += -s $file || 0; | ||||||||||||||||||||||||||||
|
Condition0%0/2
-s $file || 0
MC/DC0%0/1
-s $file || 0
-s $file
Truth table0%0/2
A
A= -s $file
| |||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||
| 53 | $size | ||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | = $size > 10_000_000_000 ? sprintf "%dGiB" , $size / 2**30 | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 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
Condition0%0/3
not defined $options->{"dir"} or $options->{"dir"}
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"}
| |||||||||||||||||||||||||||||||
| 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
Condition0%0/3
not defined $options->{"file"} or $options->{"file"}
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"}
| |||||||||||||||||||||||||||||||
| 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
Condition0%0/3
not defined $options->{"size"} or $options->{"size"}
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"}
| |||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||