File Coverage

lib/App/Perl/Tags.pm
Criterion Covered Total %
statement 39 75 52.0
branch 4 16 25.0
condition n/a
subroutine 11 17 64.7
pod 0 6 0.0
total 54 114 47.3


line stmt bran cond sub pod time code
1             #!/usr/bin/env perl
2 1     1   358032 use 5.006;
  1         8  
  1         49  
3 1     1   5 use strict; use warnings;
  1     1   5  
  1         49  
  1         9  
  1         5  
  1         70  
4              
5             package App::Perl::Tags;
6 1     1   1207 use Getopt::Long ();
  1         16443  
  1         32  
7 1     1   1825 use Pod::Usage qw/pod2usage/;
  1         56883  
  1         119  
8 1     1   1007 use File::Find::Rule;
  1         8692  
  1         9  
9              
10 1     1   735 use Perl::Tags;
  1         3  
  1         34  
11 1     1   561 use Perl::Tags::Hybrid;
  1         2  
  1         21  
12 1     1   477 use Perl::Tags::Naive::Moose; # includes ::Naive
  1         3  
  1         775  
13              
14             our $VERSION = '0.032';
15              
16             sub run {
17 0     0 0 0   my $class = shift;
18              
19               my %options = (
20                 outfile => 'perltags',
21                 files => undef,
22                 depth => 10,
23                 variables => 1,
24                 ppi => 0,
25                 prune => [ ],
26 0     0   0     help => sub { $class->usage() },
27 0     0   0     version => sub { $class->version() },
28 0         0   );
29              
30 0         0   Getopt::Long::GetOptions(
31                 \%options,
32                 'help|h',
33                 'version|v',
34                 'outfile|o=s',
35                 'files|L=s',
36                 'prune=s@',
37                 'depth|d=i',
38                 'variables|vars!',
39                 'ppi|p!',
40               );
41              
42 0 0       0   if (defined $options{files}) {
43             # Do not descend into explicitly specified files.
44 0         0     $options{depth} = 1;
45               } else {
46             # If not files are specified via -files options, we expect some
47             # paths after all the options.
48 0 0       0     $class->usage() unless @ARGV
49               }
50              
51 0         0   $options{paths} = \@ARGV;
52              
53 0         0   my $self = $class->new(%options);
54 0         0   $self->main();
55 0         0   exit();
56             }
57              
58             sub new {
59 2     2 0 1826   my ($class, %options) = @_;
60 2 100       5   $options{prune} = [ '.git', '.svn' ] unless @{ $options{prune} || [] };
  2 100       20  
61 2         9   return bless \%options, $class;
62             }
63              
64             sub version {
65 0     0 0 0   print "perl-tags v. $VERSION (Perl Tags v. $Perl::Tags::VERSION)\n";
66 0         0   exit();
67             }
68              
69             sub usage {
70 0     0 0 0   pod2usage(0);
71             }
72              
73             sub main {
74 0     0 0 0   my $self = shift;
75              
76 0         0   my %args = (
77                 max_level => $self->{depth},
78                 exts => 1,
79                 do_variables => $self->{variables},
80               );
81              
82 0         0   my @taggers = ( Perl::Tags::Naive::Moose->new( %args ) );
83 0 0       0   if ($self->{ppi}) {
84 0         0     require Perl::Tags::PPI;
85 0         0     push @taggers, Perl::Tags::PPI->new( %args );
86               }
87              
88 0         0   my $ptag = Perl::Tags::Hybrid->new( %args, taggers => \@taggers );
89              
90 0         0   my @files = do {
91 0 0       0     if (defined $self->{files}) {
92 0 0       0       if ('-' eq $self->{files}) {
93 0         0         map { chomp; $_ } <STDIN>;
  0         0  
  0         0  
94                   } else {
95 0 0       0         my $fh = IO::File->new($self->{files})
96                       or die "cannot open $$self{files} for reading: $!";
97 0         0         map { chomp; $_ } <$fh>;
  0         0  
  0         0  
98                   }
99                 } else {
100 0         0       $self->get_files;
101                 }
102               };
103              
104 0         0   $ptag->process(files => \@files);
105 0         0   $ptag->output(outfile => $self->{outfile});
106 0         0   return;
107             }
108              
109             sub get_files {
110 2     2 0 15   my $self = shift;
111 2         5   my @prune = @{ $self->{prune} };
  2         10  
112 2         3   my @paths = @{ $self->{paths} };
  2         3  
113              
114 2         16   my $rule = File::Find::Rule->new;
115              
116 2         25   my @files =
117                 $rule->or(
118                   $rule->new
119                        ->directory
120                        ->name(@prune)
121                        ->prune
122                        ->discard,
123                   $rule->new
124                     ->file,
125                 )->in(@paths);
126              
127 2         3824   return @files;
128             }
129              
130             =head1 AUTHOR
131            
132             Copyright 2009-2014, Steffen Mueller, with contributions from osfameron
133            
134             =cut
135              
136             # vim:ts=2:sw=2
137              
138             1;
139