bin/envassert

filter: Statementstmt 66.0% 35 / 53 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod n/a totaltotal 53.0% 44 / 83 CC 9 SCAR 38.2
CC
9
Cov
48%
main
90.0
BEGIN
1.0
BEGIN
1.0
CRAP 45.5
↑ 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.018';
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 = 0;
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' => \$env_desc_filename,
39 'exact|x!' => \$exact,
40 'stdin!' => \$stdin,
41 ) or pod2usage(2);
42 0 ▶pod2usage( -exitval => 0, -verbose => 2 ) if $man;
Branch: 1 branch
BranchTrueFalseTotal
if $man 0 0 0
43  
44 0 ▶sub main {
Subroutine main: not called CC=9 SCAR=45.0
45  
46 0 my @env_desc_rows;
47 0 ▶ if ($stdin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stdin) { } 0 0 0
48 0 @env_desc_rows = <>;
49 } else {
50 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
51 0 @env_desc_rows = <$fh>;
52 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
53 }
54  
55 0 ▶ my %desc = file_to_desc( $stdin ? q{STDIN} : $env_desc_filename, @env_desc_rows );
Branch: 1 branch
BranchTrueFalseTotal
$stdin ? : 0 0 0
56 0 my %parameters;
57 0 ▶ $parameters{'break_at_first_error'} = $break_at_first_error
Branch: 1 branch
BranchTrueFalseTotal
if $break_at_first_error 0 0 0
58 if $break_at_first_error;
59 0 ▶ $desc{'opts'}->{OPTION_ENV_EXACT} = $exact
Branch: 1 branch
BranchTrueFalseTotal
if defined $exact 0 0 0
60 if defined $exact;
61 0 my $r = assert( \%ENV, \%desc, \%parameters );
62 0 ▶ if ( !$r->{'success'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"success"}) 0 0 0
63 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
64 or croak 'Cannot print errors to STDOUT';
65 0 return 1;
66 }
67 0 return 0;
68 }
69  
70 0 exit main(@ARGV);
71  
72 __END__
↑ Summary blib/lib/Env/Assert/Functions.pm »