File Coverage

blib/lib/App/Du/Analyze.pm
Criterion Covered Total %
statement 54 59 91.5
branch 10 16 62.5
condition n/a
subroutine 11 11 100.0
pod 3 3 100.0
total 78 89 87.6


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