adding better json outputfile option
This commit is contained in:
parent
db326d9e9f
commit
be4c965ea9
1 changed files with 18 additions and 14 deletions
|
@ -6142,7 +6142,6 @@ if ( $opt{'template'} ne 0 ) {
|
||||||
$templateModel = file2string( $opt{'template'} );
|
$templateModel = file2string( $opt{'template'} );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
# DEFAULT REPORT TEMPLATE
|
# DEFAULT REPORT TEMPLATE
|
||||||
$templateModel = <<'END_TEMPLATE';
|
$templateModel = <<'END_TEMPLATE';
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
@ -6164,21 +6163,17 @@ END_TEMPLATE
|
||||||
}
|
}
|
||||||
|
|
||||||
sub dump_result {
|
sub dump_result {
|
||||||
if ( $opt{'debug'} ) {
|
debugprint Dumper( \%result ) if ( $opt{'debug'} );
|
||||||
debugprint Dumper( \%result );
|
|
||||||
}
|
|
||||||
|
|
||||||
debugprint "HTML REPORT: $opt{'reportfile'}";
|
debugprint "HTML REPORT: $opt{'reportfile'}";
|
||||||
|
|
||||||
if ( $opt{'reportfile'} ne 0 ) {
|
if ( $opt{'reportfile'} ne 0 ) {
|
||||||
eval { require Text::Template };
|
eval { require Text::Template };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
badprint "Text::Template Module is needed.";
|
badprint "Text::Template Module is needed.";
|
||||||
exit 1;
|
die "Text::Template Module is needed.";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $vars = { 'data' => Dumper( \%result ) };
|
my $vars = { 'data' => Dumper( \%result ) };
|
||||||
|
|
||||||
my $template;
|
my $template;
|
||||||
{
|
{
|
||||||
no warnings 'once';
|
no warnings 'once';
|
||||||
|
@ -6188,21 +6183,32 @@ sub dump_result {
|
||||||
SOURCE => $templateModel
|
SOURCE => $templateModel
|
||||||
) or die "Couldn't construct template: $Text::Template::ERROR";
|
) or die "Couldn't construct template: $Text::Template::ERROR";
|
||||||
}
|
}
|
||||||
|
|
||||||
open my $fh, q(>), $opt{'reportfile'}
|
open my $fh, q(>), $opt{'reportfile'}
|
||||||
or die
|
or die
|
||||||
"Unable to open $opt{'reportfile'} in write mode. please check permissions for this file or directory";
|
"Unable to open $opt{'reportfile'} in write mode. please check permissions for this file or directory";
|
||||||
$template->fill_in( HASH => $vars, OUTPUT => $fh );
|
$template->fill_in( HASH => $vars, OUTPUT => $fh );
|
||||||
close $fh;
|
close $fh;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $opt{'json'} ne 0 ) {
|
if ( $opt{'json'} ne 0 ) {
|
||||||
eval { require JSON };
|
eval { require JSON };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
print "$bad JSON Module is needed.\n";
|
print "$bad JSON Module is needed.\n";
|
||||||
exit 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $json = JSON->new->allow_nonref;
|
my $json = JSON->new->allow_nonref;
|
||||||
print $json->utf8(1)->pretty( ( $opt{'prettyjson'} ? 1 : 0 ) )
|
print $json->utf8(1)->pretty( ( $opt{'prettyjson'} ? 1 : 0 ) )
|
||||||
->encode( \%result );
|
->encode( \%result ) unless ( $opt{'silent'} );
|
||||||
|
|
||||||
|
if ( $opt{'outputfile'} ne 0 ) {
|
||||||
|
open my $fh, q(>), $opt{'outputfile'}
|
||||||
|
or die
|
||||||
|
"Unable to open $opt{'outputfile'} in write mode. please check permissions for this file or directory";
|
||||||
|
print $fh $json->utf8(1)->pretty( ( $opt{'prettyjson'} ? 1 : 0 ) );
|
||||||
|
close $fh;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6212,9 +6218,7 @@ sub which {
|
||||||
my @path_array = split /:/, $ENV{'PATH'};
|
my @path_array = split /:/, $ENV{'PATH'};
|
||||||
|
|
||||||
for my $path (@path_array) {
|
for my $path (@path_array) {
|
||||||
if ( -x "$path/$prog_name" ) {
|
return "$path/$prog_name" if ( -x "$path/$prog_name" );
|
||||||
return "$path/$prog_name";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue