bin/envassert

filter: Statementstmt 66.0% 35 / 53 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod n/a totaltotal 54.3% 44 / 81 CC 8 SCAR 35.4
CC
8
Cov
49%
main
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 34.4
↑ Summary blib/lib/Env/Assert/Functions.pm »
1 #!/usr/bin/env perl
2 ## no critic (ControlStructures::ProhibitPostfixControls)
3 ## no critic (ValuesAndExpressions::ProhibitConstantPragma)
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use open ':std', IO => ':encoding(UTF-8)';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: Ensure that the environment variables match what you need, or abort.
9  
10 # PODNAME: envassert
11  
12 2 our $VERSION = '0.015';
13  
14 2 ▶use English qw( -no_match_vars ); # Avoids regex performance penalty in perl 5.18 and earlier
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Getopt::Long qw( :config auto_version auto_help );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 ▶use Env::Assert::Functions qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 local $OUTPUT_AUTOFLUSH = 1;
22  
23 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 YEAR_START => 1900,
25 MONTH_START => 1,
26 ENV_DESC_FILENAME => '.envdesc',
27 INDENT => q{ },
28 2 };
29  
30 2 my $man = 0;
31 2 my $break_at_first_error;
32 2 my $env_desc_filename = ENV_DESC_FILENAME;
33 2 my $exact;
34 2 my $stdin = 0;
35 2 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("man", \$man, "break-at-first-error|b!", \$break_at_first_error, "env-description|e=s", \$env_desc_filename, "exact|x!", \$exact, "stdin!", \$stdin) or pod2usage(2) 0 0 0
36 'man' => \$man,
37 'break-at-first-error|b!' => \$break_at_first_error,
38 'env-description|e=s' =>,
39 \$env_desc_filename,
40 'exact|x!' => \$exact,
41 'stdin!' => \$stdin,
42 ) or pod2usage(2);
43 0 ▶pod2usage( -exitval => 0, -verbose => 2 ) if $man;
Branch: 1 branch
BranchTrueFalseTotal
if $man 0 0 0
44  
45 0 ▶sub main {
Subroutine main: not called CC=8 SCAR=42.8
46  
47 0 my @env_desc_rows;
48 0 ▶ if ($stdin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stdin) { } 0 0 0
49 0 @env_desc_rows = <>;
50 }
51 else {
52 0 ▶ open my $fh, q{<}, $env_desc_filename or croak "Cannot open file '$env_desc_filename'";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $env_desc_filename or croak("Cannot open file '${env_desc_filename}'") 0 0 0
53 0 @env_desc_rows = <$fh>;
54 0 ▶ close $fh or croak "Cannot close file '$env_desc_filename'";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or croak("Cannot close file '${env_desc_filename}'") 0 0 0
55 }
56  
57 0 my $desc = file_to_desc(@env_desc_rows);
58 0 my %parameters;
59 0 ▶ $parameters{'break_at_first_error'} = $break_at_first_error
Branch: 1 branch
BranchTrueFalseTotal
if defined $break_at_first_error 0 0 0
60 if defined $break_at_first_error;
61 0 ▶ $desc->{'options'}->{'exact'} = $exact
Branch: 1 branch
BranchTrueFalseTotal
if defined $exact 0 0 0
62 if defined $exact;
63 0 my $r = assert( \%ENV, $desc, \%parameters );
64 0 ▶ if ( !$r->{'success'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"success"}) 0 0 0
65 0 ▶ print {*STDOUT} report_errors( $r->{'errors'} )
Branch: 1 branch
BranchTrueFalseTotal
print {*STDOUT;} report_errors($r->{"errors"}) or croak("Cannot print errors to STDOUT") 0 0 0
66 or croak 'Cannot print errors to STDOUT';
67 0 return 1;
68 }
69 0 return 0;
70 }
71  
72 0 exit main(@ARGV);
73  
74 __END__
↑ Summary blib/lib/Env/Assert/Functions.pm »