Website/Command.pm

filter: Statementstmt 40.2% 33 / 82 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 52.6% 10 / 19 Podpod 22.2% 2 / 9 totaltotal 28.1% 45 / 160 CC 19 SCAR 29.3
CC
19
Cov
27%
validate_or_create_dir
56.0
meetings
30.0
validate_required_dir
20.0
CRAP 18.8
↑ Summary Website/Command/Build.pm »
1 package App::PM::Website::Command;
2 {
3 2 $App::PM::Website::Command::VERSION = '0.131611';
4 }
5 #use App::Cmd::Setup -command;
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use base 'App::Cmd::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Config::YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Date::Parse qw(str2time);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Lingua::EN::Numbers::Ordinate qw(ordinate);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 #ABSTRACT: Parent class for App::PM::Website commands
18  
19 sub opt_spec
20 0 ▶{
Subroutine opt_spec: not called CC=1 SCAR=6.9
Pod documented
21 0 my ( $class, $app ) = @_;
22 return (
23 0 $class->options($app),
24 [ 'config-file=s' => "path to configuration file",
25 { required => 1, default => "config/pm-website.yaml"}],
26 [],
27 [ 'help|h!' => "show this help" ],
28 [ 'dry-run|n!' => "take no action" ],
29 [ 'verbose|v+' => "increase verbosity" ],
30 );
31 }
32  
33 sub validate_args
34 0 ▶{
Subroutine validate_args: not called CC=2 SCAR=17.9
Pod documented
35 0 my ( $self, $opt, $args ) = @_;
36 0 ▶ die $self->_usage_text if $opt->{help};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"help"} 0 0 0
37 0 $self->validate_config( $opt, $args );
38 0 $self->validate( $opt, $args );
39 }
40  
41 sub validate_required_dir
42 0 ▶{
Subroutine validate_required_dir: not called CC=4 SCAR=30.0
Pod undocumented
43 0 my ($self, $opt, $dir) = @_;
44 0 my $c = $self->{config}{config}{website};
45 0 ▶ $opt->{$dir} ||= $c->{$dir};
Condition0%0/3
$opt->{$dir} ||= $c->{$dir}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt->{$dir} ||= $c->{$dir}
$opt->{$dir} $c->{$dir}
Truth table0%0/3
A ||= B
A= $opt->{$dir}B= $c->{$dir}
ABresult
1X1
011
000
46 die $self->usage_error("$dir is required")
47 0 ▶ if !$opt->{$dir};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->{$dir} 0 0 0
48  
49 die $self->usage_error(
50 "$dir does not exist: $opt->{$dir}")
51 0 ▶ if !-d $opt->{$dir};
Branch: 1 branch
BranchTrueFalseTotal
unless -d $opt->{$dir} 0 0 0
52  
53 0 return 1
54 }
55 sub validate_or_create_dir
56 0 ▶{
Subroutine validate_or_create_dir: not called CC=7 SCAR=40.3
Pod undocumented
57 0 my ($self, $opt, $dir) = @_;
58 0 my $c = $self->{config}{config}{website};
59 0 ▶ $opt->{$dir} ||= $c->{$dir};
Condition0%0/3
$opt->{$dir} ||= $c->{$dir}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt->{$dir} ||= $c->{$dir}
$opt->{$dir} $c->{$dir}
Truth table0%0/3
A ||= B
A= $opt->{$dir}B= $c->{$dir}
ABresult
1X1
011
000
60  
61 die $self->usage_error("$dir is required")
62 0 ▶ if !$opt->{$dir};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->{$dir} 0 0 0
63  
64 0 ▶ if ( ! -d $opt->{$dir} )
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $opt->{$dir}) 0 0 0
65 {
66 print "creating build dir: $opt->{$dir}\n"
67 0 ▶ if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 0 0 0
68 0 ▶ if ( !$opt->{dry_run} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt->{"dry_run"}) 0 0 0
69 {
70 0 ▶ mkdir( $opt->{$dir} )
Branch: 1 branch
BranchTrueFalseTotal
mkdir $opt->{$dir} or die $self->usage_error("failed to make output directory $opt->{$dir} : $!") 0 0 0
71 or die $self->usage_error(
72 "failed to make output directory $opt->{$dir} : $!");
73 }
74 }
75  
76 0 return 1
77 }
78  
79  
80 sub validate_config
81 0 ▶{
Subroutine validate_config: not called CC=2 SCAR=17.9
Pod undocumented
82 0 my ( $self, $opt, $args ) = @_;
83 $self->{config} = Config::YAML->new( config => $opt->{config_file} )
84 0 ▶ or die $self->usage_error("failed to open configuration file: $!");
Branch: 1 branch
BranchTrueFalseTotal
$self->{"config"} = "Config::YAML"->new("config", $opt->{"config_file"}) or die $self->usage_error("failed to open configuration file: $!") 0 0 0
85 }
86  
87 sub meetings
88 0 ▶{
Subroutine meetings: not called CC=5 SCAR=34.0
Pod undocumented
89 0 my $self = shift;
90 0 my $meetings = $self->{config}->get_meetings;
91 0 my $strp = new DateTime::Format::Strptime(
92 pattern => '%Y-%b-%d',
93 locale => 'en',
94 );
95 0 my $strp_std = new DateTime::Format::Strptime(
96 pattern => '%A %B %e, %Y',
97 locale => 'en',
98 );
99 0 my $strp_pretty = new DateTime::Format::Strptime(
100 pattern => '%A the %e',
101 locale => 'en',
102 );
103  
104 0 for my $meeting (@$meetings)
105 {
106 0 ▶ $meeting->{epoch} ||= str2time( $meeting->{event_date}, 'PST' );
Condition0%0/3
$meeting->{"epoch"} ||= str2time($meeting->{"event_date"}, "PST")
l!l&&r!l&&!r
000
MC/DC0%0/2
$meeting->{"epoch"} ||= str2time($meeting->{"event_date"}, "PST")
$meeting->{"epoch"} str2time($meeting->{"event_date"}, "PST")
Truth table0%0/3
A ||= B
A= $meeting->{"epoch"}B= str2time($meeting->{"event_date"}, "PST")
ABresult
1X1
011
000
107 0 my $dt = DateTime->from_epoch( epoch => $meeting->{epoch} );
108 0 $meeting->{dt} = $dt;
109 0 ▶ $meeting->{ds1} ||= $strp->format_datetime($dt);
Condition0%0/3
$meeting->{"ds1"} ||= $strp->format_datetime($dt)
l!l&&r!l&&!r
000
MC/DC0%0/2
$meeting->{"ds1"} ||= $strp->format_datetime($dt)
$meeting->{"ds1"} $strp->format_datetime($dt)
Truth table0%0/3
A ||= B
A= $meeting->{"ds1"}B= $strp->format_datetime($dt)
ABresult
1X1
011
000
110 0 ▶ $meeting->{ds_std} ||= $strp_std->format_datetime($dt);
Condition0%0/3
$meeting->{"ds_std"} ||= $strp_std->format_datetime($dt)
l!l&&r!l&&!r
000
MC/DC0%0/2
$meeting->{"ds_std"} ||= $strp_std->format_datetime($dt)
$meeting->{"ds_std"} $strp_std->format_datetime($dt)
Truth table0%0/3
A ||= B
A= $meeting->{"ds_std"}B= $strp_std->format_datetime($dt)
ABresult
1X1
011
000
111 0 my $pretty = $strp_pretty->format_datetime($dt);
112 0 $pretty =~ s/(\d+) \s* $/ordinate($1)/ex;
113 0 $meeting->{event_date_pretty} = $pretty;
114 }
115 0 sort { $b->{epoch} <=> $a->{epoch} } @$meetings;
116 }
117  
118 sub today
119 0 ▶{
Subroutine today: not called CC=2 SCAR=17.9
Pod undocumented
120 0 my ($class) = @_;
121 0 ▶ return unless $class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 0 0 0
122 0 $class->date_as_ymd();
123 }
124  
125 sub yesterday
126 0 ▶{
Subroutine yesterday: not called CC=2 SCAR=17.9
Pod undocumented
127 0 my ($class) = @_;
128 0 ▶ return unless $class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 0 0 0
129 0 $class->date_as_ymd( time - 24 * 60 * 60 );
130 }
131  
132 sub date_as_ymd
133 0 ▶{
Subroutine date_as_ymd: not called CC=2 SCAR=17.9
Pod undocumented
134 0 my ( $class, $time ) = @_;
135 0 ▶ $time ||= time();
Condition0%0/2
$time ||= time
l!l
00
MC/DC0%0/1
$time ||= time
$time
Truth table0%0/2
A
A= $time
Aresult
11
00
136 0 return strftime( "%Y-%m-%d", localtime($time) );
137 }
138  
139 2 1;
140  
141 __END__
↑ Summary Website/Command/Build.pm »