File Coverage

bin/envassert
Criterion Covered Total %
statement 35 53 66.0
branch 0 18 0.0
condition n/a
subroutine 9 10 90.0
pod n/a
total 44 81 54.3


line stmt bran cond sub pod time code
1             #!/usr/bin/env perl
2             ## no critic (ControlStructures::ProhibitPostfixControls)
3             ## no critic (ValuesAndExpressions::ProhibitConstantPragma)
4 2     2   11662 use strict;
  2         4  
  2         91  
5 2     2   12 use warnings;
  2         3  
  2         150  
6 2     2   1176 use open ':std', IO => ':encoding(UTF-8)';
  2         3527  
  2         16  
7              
8             # ABSTRACT: Ensure that the environment variables match what you need, or abort.
9              
10             # PODNAME: envassert
11              
12 2         203005 our $VERSION = '0.015';
13              
14 2     2   78452 use English qw( -no_match_vars ); # Avoids regex performance penalty in perl 5.18 and earlier
  2         6467  
  2         15  
15 2     2   2182 use Getopt::Long qw( :config auto_version auto_help );
  2         31920  
  2         14  
16 2     2   438 use Carp;
  2         4  
  2         143  
17 2     2   1098 use Pod::Usage;
  2         100289  
  2         337  
18              
19 2     2   1441 use Env::Assert::Functions qw( :all );
  2         11  
  2         430  
20              
21 2         19 local $OUTPUT_AUTOFLUSH = 1;
22              
23             use constant {
24 2         173903 YEAR_START => 1900,
25             MONTH_START => 1,
26             ENV_DESC_FILENAME => '.envdesc',
27             INDENT => q{ },
28 2     2   17 };
  2         12  
29              
30 2         5 my $man = 0;
31 2         3 my $break_at_first_error;
32 2         6 my $env_desc_filename = ENV_DESC_FILENAME;
33 2         4 my $exact;
34 2         4 my $stdin = 0;
35 2 0       19 GetOptions(
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 0       0 pod2usage( -exitval => 0, -verbose => 2 ) if $man;
44              
45             sub main {
46              
47 0     0     my @env_desc_rows;
48 0 0         if ($stdin) {
49 0           @env_desc_rows = <>;
50             }
51             else {
52 0 0         open my $fh, q{<}, $env_desc_filename or croak "Cannot open file '$env_desc_filename'";
53 0           @env_desc_rows = <$fh>;
54 0 0         close $fh or croak "Cannot close file '$env_desc_filename'";
55             }
56              
57 0           my $desc = file_to_desc(@env_desc_rows);
58 0           my %parameters;
59 0 0         $parameters{'break_at_first_error'} = $break_at_first_error
60             if defined $break_at_first_error;
61 0 0         $desc->{'options'}->{'exact'} = $exact
62             if defined $exact;
63 0           my $r = assert( \%ENV, $desc, \%parameters );
64 0 0         if ( !$r->{'success'} ) {
65 0 0         print {*STDOUT} report_errors( $r->{'errors'} )
  0            
66             or croak 'Cannot print errors to STDOUT';
67 0           return 1;
68             }
69 0           return 0;
70             }
71              
72 0         0 exit main(@ARGV);
73              
74             __END__