File Coverage

blib/lib/App/RunCron/CLI.pm
Criterion Covered Total %
statement 47 47 100.0
branch 9 12 75.0
condition 2 3 66.6
subroutine 11 11 100.0
pod 0 3 0.0
total 69 76 90.7


line stmt bran cond sub pod time code
1             package App::RunCron::CLI;
2 1     1   49233 use strict;
  1         1  
  1         33  
3 1     1   4 use warnings;
  1         2  
  1         22  
4 1     1   4 use utf8;
  1         2  
  1         6  
5              
6 1     1   685 use Getopt::Long;
  1         10114  
  1         8  
7 1     1   1156 use Pod::Usage;
  1         47924  
  1         130  
8 1     1   766 use Time::Piece;
  1         10237  
  1         6  
9 1     1   746 use YAML::Tiny ();
  1         5705  
  1         50  
10              
11 1     1   579 use App::RunCron;
  1         5  
  1         387  
12              
13             sub new {
14 3     3 0 6905 my ($class, @argv) = @_;
15              
16 3         12 local @ARGV = @argv;
17 3         32 my $p = Getopt::Long::Parser->new(
18             config => [qw/posix_default no_ignore_case bundling auto_help/],
19             );
20 3 50       407 $p->getoptions(\my %opt, qw/
21             logfile=s
22             timestamp
23             print
24             reporter=s
25             error_reporter=s
26             common_reporter=s
27             announcer=s
28             tag|t=s
29             config|c=s
30             /) or pod2usage(1);
31              
32 3         1939 $opt{command} = [@ARGV];
33 3         8 for my $rep (qw/reporter error_reporter announcer/){
34 9 50       19 $opt{$rep} = ucfirst $opt{$rep} if $opt{$rep};
35             }
36 3         12 $class->new_with_options(%opt);
37             }
38              
39             sub new_with_options {
40 3     3 0 32 my ($class, %opt) = @_;
41              
42 3 100       9 if ($opt{logfile}) {
43 2         8 my $now = localtime;
44 2         131 $opt{logfile} = $now->strftime($opt{logfile});
45             }
46              
47 3 100 66     166 if (!$opt{config} && -e 'runcron.yml') {
48 2         5 $opt{config} = 'runcron.yml';
49             }
50 3 50       10 if ($opt{config}) {
51 3         5 my $config_file = $opt{config};
52 3         5 my $conf = eval { YAML::Tiny::LoadFile($config_file) };
  3         12  
53 3 100       6121 if ($@) {
54 1         51 warn "Bad config: $config_file: $@";
55             }
56             else {
57 2         21 %opt = (
58             %$conf,
59             %opt,
60             );
61             }
62             }
63              
64             bless {
65 3         34 runner => App::RunCron->new(%opt),
66             }, $class;
67             }
68              
69             sub run {
70 1     1 0 5028 shift->{runner}->run
71             }
72              
73             1;