File Coverage

blib/lib/App/Du/Analyze.pm
Criterion Covered Total %
statement 51 56 91.0
branch 10 16 62.5
condition n/a
subroutine 10 10 100.0
pod 3 3 100.0
total 74 85 87.0


line stmt bran cond sub pod time code
1             package App::Du::Analyze;
2              
3 1     1   91861 use strict;
  1         1  
  1         33  
4 1     1   4 use warnings;
  1         1  
  1         26  
5              
6 1     1   4 use autodie;
  1         1  
  1         6  
7              
8             our $VERSION = '0.2.0';
9              
10 1     1   4595 use Getopt::Long qw( GetOptionsFromArray );
  1         8719  
  1         9  
11 1     1   869 use Pod::Usage;
  1         37423  
  1         159  
12              
13 1     1   490 use App::Du::Analyze::Filter;
  1         3  
  1         370  
14              
15             sub argv
16             {
17 24     24 1 32 my $self = shift;
18              
19 24 100       71 if (@_)
20             {
21 12         32 $self->{argv} = shift;
22             }
23              
24 24         66 return $self->{argv};
25             }
26              
27             sub new
28             {
29 12     12 1 32930 my $class = shift;
30              
31 12         36 my $self = bless {}, $class;
32              
33 12         50 $self->_init(@_);
34              
35 12         58 return $self;
36             }
37              
38             sub _init
39             {
40 12     12   25 my ($self, $args) = @_;
41              
42 12         54 $self->argv($args->{argv});
43              
44 12         25 return;
45             }
46              
47             sub run
48             {
49 12     12 1 17 my ($self) = @_;
50              
51 12         27 my $prefix = "";
52 12         21 my $depth = 1;
53 12         23 my $sort = 1;
54 12         23 my $man = 0;
55 12         19 my $help = 0;
56 12         19 my $version = 0;
57              
58 12         21 my @argv = @{$self->argv};
  12         38  
59              
60 12 50       104 GetOptionsFromArray(
61             \@argv,
62             "prefix|p=s" => \$prefix,
63             "depth|d=n" => \$depth,
64             "sort" => \$sort,
65             "help|h" => \$help,
66             "man" => \$man,
67             "version" => \$version,
68             ) or pod2usage(2);
69              
70 12 50       6434 if ($help)
71             {
72 0         0 pod2usage(1)
73             }
74              
75 12 50       46 if ($man)
76             {
77 0         0 pod2usage(-verbose => 2);
78             }
79              
80 12 50       39 if ($version)
81             {
82 0         0 print "analyze-du.pl version $VERSION\n";
83 0         0 exit(0);
84             }
85              
86 12         16 my $in_fh;
87              
88             my $filename;
89 12 100       46 if (!defined ($filename = $ENV{ANALYZE_DU_INPUT_FN}))
90             {
91 6         12 $filename = shift(@argv);
92             }
93              
94 12 50       36 if (!defined($filename))
95             {
96 0         0 $in_fh = \*STDIN;
97             }
98             else
99             {
100 12         60 open $in_fh, '<', $filename;
101             }
102              
103 12         3745 App::Du::Analyze::Filter->new(
104             {
105             prefix => $prefix,
106             depth => $depth,
107             should_sort => $sort,
108             }
109             )->filter($in_fh, \*STDOUT);
110              
111 12 50       94 if (defined($filename))
112             {
113 12         69 close($in_fh);
114             }
115              
116 12         1874 return;
117             }
118              
119             1;
120              
121             __END__