| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #=============================================== | 
| 2 |  |  |  |  |  |  | package Banal::Utils::General; | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 1 |  |  | 1 |  | 927 | use utf8; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 5 |  |  |  |  |  |  | require Exporter; | 
| 6 | 1 |  |  | 1 |  | 32 | no warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 1 |  |  | 1 |  | 6 | use Data::Dumper; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 503 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | @ISA = qw(Exporter); | 
| 11 |  |  |  |  |  |  | @EXPORT_OK = qw( run_cmd run_perl debug_dump_vars); | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | ##############################################################################" | 
| 15 |  |  |  |  |  |  | # Utility functions | 
| 16 |  |  |  |  |  |  | ##############################################################################" | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | #------------------------------------------------------------- | 
| 19 |  |  |  |  |  |  | sub run_cmd { | 
| 20 | 0 |  |  | 0 | 1 |  | my ($opts, $cmd) 	= @_; | 
| 21 | 0 |  | 0 |  |  |  | my $verbose 		= $opts->{verbose} || $opts->{debug}; | 
| 22 | 0 |  |  |  |  |  | my $dryrun			= $opts->{dryrun}; | 
| 23 | 0 | 0 |  |  |  |  | my $prompt			= $dryrun ? 'sys  would >  ' : 'sys  cmd >  '; | 
| 24 | 0 | 0 |  |  |  |  | return unless $cmd; | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 0 | 0 |  |  |  |  | print $prompt . $cmd . "\n" if $verbose; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 0 |  |  |  |  |  | my $output; | 
| 29 | 0 | 0 |  |  |  |  | unless ($dryrun) 	{	$output = `$cmd`;													} | 
|  | 0 |  |  |  |  |  |  | 
| 30 | 0 | 0 |  |  |  |  | else 				{ 	$output = $dryrun ? 'Command NOT executed (dry-run mode)' : eval($cmd); } | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 0 | 0 | 0 |  |  |  | print "$output\n" if ($output && $verbose > 5); | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | #------------------------------------------------------------- | 
| 37 |  |  |  |  |  |  | sub run_perl { | 
| 38 | 0 |  |  | 0 | 1 |  | my ($opts, $cmd) 	= @_; | 
| 39 | 0 |  | 0 |  |  |  | my $verbose 		= $opts->{verbose} || $opts->{debug}; | 
| 40 | 0 |  |  |  |  |  | my $dryrun			= $opts->{dryrun}; | 
| 41 | 0 | 0 |  |  |  |  | my $prompt			= $dryrun ? 'perl would >  ' : 'perl cmd >  '; | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 0 | 0 |  |  |  |  | return unless $cmd; | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 0 | 0 |  |  |  |  | print $prompt . $cmd . "\n" if $verbose; | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 0 |  |  |  |  |  | my $output; | 
| 48 | 0 | 0 |  |  |  |  | unless ($dryrun) 	{	$output = eval($cmd);													} | 
|  | 0 |  |  |  |  |  |  | 
| 49 | 0 | 0 |  |  |  |  | else 				{ 	$output = $dryrun ? 'Command NOT executed (dry-run mode)' : eval($cmd); } | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 0 | 0 | 0 |  |  |  | print "$output\n" if ($output && $verbose > 5); | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | #--------------------------------- | 
| 55 |  |  |  |  |  |  | sub debug_dump_vars { | 
| 56 | 0 |  |  | 0 | 1 |  | my $msg = shift; | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 0 |  |  |  |  |  | print STDERR "$msg:DUMP:\n"; | 
| 59 | 0 |  |  |  |  |  | $Data::Dumper::Sortkeys = 1; | 
| 60 | 0 |  |  |  |  |  | print STDERR Data::Dumper->Dump([@_]); | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | 1; | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | __END__ |