File Coverage

blib/lib/OrePAN2/CLI/Inject.pm
Criterion Covered Total %
statement 45 52 86.5
branch 9 18 50.0
condition 3 6 50.0
subroutine 9 9 100.0
pod 0 2 0.0
total 66 87 75.8


line stmt bran cond sub pod time code
1             package OrePAN2::CLI::Inject;
2              
3 3     3   20 use strict;
  3         6  
  3         111  
4 3     3   13 use warnings;
  3         6  
  3         122  
5 3     3   1600 use utf8;
  3         819  
  3         43  
6              
7 3     3   2365 use Getopt::Long ();
  3         44502  
  3         105  
8 3     3   998 use OrePAN2 ();
  3         6  
  3         49  
9 3     3   1010 use OrePAN2::Repository ();
  3         13  
  3         169  
10 3     3   1789 use Pod::Usage qw( pod2usage );
  3         166100  
  3         2008  
11              
12             sub new {
13 3     3 0 13 my $class = shift;
14 3         23 bless {}, $class;
15             }
16              
17             sub run {
18 3     3 0 15 my ( $self, @args ) = @_;
19              
20 3         7 my $version;
21 3         9 my $generate_index = 1;
22 3         7 my $author = 'DUMMY';
23 3         8 my $author_subdir = q{};
24 3         9 my $simple;
25             my $text;
26 3         5 my $enable_cache = 0;
27 3         39 my $p = Getopt::Long::Parser->new(
28             config => [qw(posix_default no_ignore_case auto_help)] );
29 3         4794 $p->getoptions(
30             'version!' => \$version,
31             'generate-index!' => \$generate_index,
32             'author=s' => \$author,
33             'author_subdir=s' => \$author_subdir,
34             'simple!' => \$simple,
35             'text!' => \$text,
36             'cache!' => \$enable_cache,
37             );
38              
39 3 50       3514 if ($version) {
40 0         0 print "orepan2: $OrePAN2::VERSION\n";
41             }
42 3 50       116 my $directory = pop @ARGV or pod2usage(
43             -input => $0,
44             );
45              
46 3         51 my $repository = OrePAN2::Repository->new(
47             directory => $directory,
48             compress_index => !$text,
49             simple => $simple,
50             );
51 3 50       16709 if (@ARGV) {
52 3         10 for (@ARGV) {
53 3 50       16 next unless /\S/;
54 3 100 100     61 next if $enable_cache && $repository->has_cache($_);
55              
56 2         14 my $tarpath = $repository->inject(
57             $_,
58             { author => $author, author_subdir => $author_subdir }
59             );
60 2         94 print "Wrote $tarpath from $_\n";
61             }
62             }
63             else {
64 0         0 while (<>) {
65 0         0 chomp;
66 0 0       0 next unless /\S/;
67 0 0 0     0 next if $enable_cache && $repository->has_cache($_);
68              
69 0         0 my $tarpath = $repository->inject(
70             $_,
71             { author => $author, author_subdir => $author_subdir }
72             );
73 0         0 print "Wrote $tarpath from $_\n";
74             }
75             }
76              
77 3 100       81 return unless $repository->cache->is_dirty;
78              
79 2         86 $repository->save_cache;
80              
81 2 50       7140 if ($generate_index) {
82 2         13 $repository->make_index();
83             }
84             }
85              
86             1;
87