script/check_web2.pl untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 97 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use strict;
4 use warnings;
5  
6 # PODNAME: check_web2
7 # ABSTRACT: allows checking of website according to configured specifications
8  
9 use v5.10.1;
10  
11 use Getopt::Long;
12  
13 use Params::Util qw(_ARRAY);
14  
15 use WWW::Mechanize::Script::Util qw(:ALL);
16 use WWW::Mechanize::Script;
17  
18 our $VERSION = '0.100';
19 my %opts;
20 my @options = ( "file=s", "help|h", "usage|?" );
21  
22 GetOptions( \%opts, @options ) or pod2usage(2);
23  
24 defined( $opts{help} )
25 and $opts{help}
26 and pod2usage(
27 {
28 -verbose => 2,
29 -exitval => 0
30 }
31 );
32 defined( $opts{usage} ) and $opts{usage} and pod2usage(1);
33 opt_required_all( \%opts, qw(file) );
34  
35 my %cfg = load_config( \%opts );
36 do
37 {
38 my %cfgvar = ( OPTS_FILE => $opts{file} );
39 my $cfgkeys = join( "|", keys %cfgvar );
40 $cfg{summary}->{target} =~ s/@($cfgkeys)[@]/$cfgvar{$1}/ge;
41 $cfg{report}->{target} =~ s/@($cfgkeys)[@]/$cfgvar{$1}/ge;
42 } while (0);
43  
44 my $wms = WWW::Mechanize::Script->new( \%cfg );
45  
46 _ARRAY( $cfg{wtscript_extensions} )
47 and Config::Any::WTScript->extensions( @{ $cfg{wtscript_extensions} } );
48 my @script_files = find_scripts( \%cfg, $opts{file} );
49  
50 my ( $code, @msgs ) = (0);
51 eval {
52 my @script;
53 my $scripts = Config::Any->load_files(
54 {
55 files => [@script_files],
56 use_ext => 1,
57 flatten_to_hash => 1,
58 }
59 );
60 foreach my $filename (@script_files)
61 {
62 defined( $scripts->{$filename} )
63 or next; # file not found or not parsable ...
64 # merge into default and previous loaded config ...
65 push( @script, @{ $scripts->{$filename} } );
66 }
67 ( $code, @msgs ) = $wms->run_script(@script);
68 };
69 $@ and say("UNKNOWN - $@");
70 exit( $@ ? 255 : $code );
71  
72 __END__