lib/Log/Shiras/Unhide.pm

filter: Statementstmt 91.4% 128 / 140 Branchbran 67.6% 23 / 34 Conditioncond 36.3% 4 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 20 / 20 Podpod n/a totaltotal 82.9% 175 / 211 CC 24 SCAR 23.6
CC
24
Cov
84%
import
26.0
_resurrector_loader
5.0
_pm_search
4.0
CRAP 10.6
« blib/lib/Log/Shiras/Report/Test2Diag.pm ↑ Summary lib/Log/Shiras/Report/MetaMessage.pm »
1 package Log::Shiras::Unhide;
2 2 our $AUTHORITY = 'cpan:JANDREW';
3 2 ▶use version; our $VERSION = version->declare("v0.48.0");
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 # [rt.cpan.org #84818]
9 2 ▶use if $^O eq "MSWin32", "Win32";
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use File::Temp;# qw(tempfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 #~ $File::Temp::DEBUG = 1;
13 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Module::Runtime qw( require_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 use lib
17 2 ▶ '../../../lib',
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ;
19  
20 2 ▶use constant IMPORT_DEBUG => 0; # Unhide Dev testing only
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use constant INTERNAL_DEBUG => 0; # Unhide Dev testing only
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use constant VIEW_TRANSFORM => 0; # Unhide Dev testing only
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 my $my_unhide_skip_check = qr/(
24 ^Archive.Zip| ^attributes| ^AutoLoader| ^B\.pm|
25 ^B.(Op_|Deparse)| ^B.(Hooks)| ^Carp| ^Class|
26 ^Clone| ^common| ^Compress.Raw| ^Cwd|
27 ^Data.OptList| ^DateTime(?!X)| ^Devel| ^Encode|
28 ^Eval| ^Exporter| ^feature| ^File|
29 ^Filter| ^if\.pm| ^integer| ^IO.File|
30 ^JSON| ^List| ^Log.Shiras.Unhide| ^metaclass|
31 ^Module| ^Moose(?!X)| ^MooseX.Has| ^MooseX.Non|
32 ^MooseX.Singleton| ^MooseX.Strict| ^MooseX.Type| ^MRO|
33 ^namespace| ^Package| ^Params| ^parent|
34 ^PerlIO| ^POSIX| ^re\.pm| ^SelfLoader|
35 ^SetDual| ^Smart| ^Sub| ^Test2|
36 ^Tie| ^Text| ^Time.Local| ^Try|
37 ^Type| ^unicore| ^UNIVERSAL| ^utf8|
38 ^Variable| ^Win32| ^XML|
39 ^YAML
40 )/x;
41 2 my $run_once_hash;
42 2 our $strip_match;
43 2 my $temp_dir;
44  
45  
46 #########1 import 2#########3#########4#########5#########6#########7#########8#########9
47  
48 2 ▶sub import {
Subroutine import: called CC=15 SCAR=32.6
49 2 my( $class, @args ) = @_;
50 # Handle re-call
51 2 ▶ if( $strip_match ){
Branch: 1 branch
BranchTrueFalseTotal
if ($Log::Shiras::Unhide::strip_match) 0 2 2
52 0 warn "------------>Trying to reload Unhide with string: $strip_match !!!!!!!!!\n" if IMPORT_DEBUG;
53 0 _resurrector_init();
54 0 return 1;
55 }
56  
57 2 ▶ warn "Received args:" . join( '~|~', @args ) if @args and IMPORT_DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if @args and 0 0 2 2
Condition50%1/2
@args and 0
!ll
02
MC/DC0%0/1
@args and 0
@args
Truth table50%1/2
A
A= @args
Aresult
00
11
58  
59 # Build a temporary directory
60 2 $temp_dir = File::Temp->newdir( CLEANUP => 1 );
61  
62 # Handle versions
63 2 ▶ if( $args[0] and $args[0] =~ /^v?\d+\.?\d*/ ){# Version check since import highjacks the built in
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] and $args[0] =~ /^v?\d+\.?\d*/) 0 2 2
Condition33%1/3
$args[0] and $args[0] =~ /^v?\d+\.?\d*/
!ll&&!rl&&r
020
MC/DC0%0/2
$args[0] and $args[0] =~ /^v?\d+\.?\d*/
$args[0] $args[0] =~ /^v?\d+\.?\d*/
Truth table33%1/3
A and B
A= $args[0]B= $args[0] =~ /^v?\d+\.?\d*/
ABresult
0X0
100
111
64 0 warn "Running version check on version: $args[0]" if IMPORT_DEBUG;
65 0 my $result = $VERSION <=> version->parse( $args[0]);
66 0 warn "Tested against version -$VERSION- gives result: $result" if IMPORT_DEBUG;
67 0 ▶ if( $result < 0 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($result < 0) 0 0 0
68 0 die "Version -$args[0]- requested for Log::Shiras::Switchboard " .
69 "- the installed version is: $VERSION";
70 }
71 0 shift @args;
72 }
73  
74 # Build/Load the string strippers
75 2 my @strip_list;
76 2 for my $flag ( @args ){
77 5 warn "Arrived at import with flag: $flag" if IMPORT_DEBUG;
78 5 ▶ if( $flag =~ /^:([A-Za-z]+)$/ ){# Handle text based flags
Branch: 1 branch
BranchTrueFalseTotal
if ($flag =~ /^:([A-Za-z]+)$/) { } 5 0 5
79 5 my $strip = $1;
80 5 ▶ push @strip_list, $strip eq 'debug' ? 'LogSD' : $strip;
Branch: 1 branch
BranchTrueFalseTotal
$strip eq 'debug' ? : 1 4 5
81 }else{
82 0 die "Flag -$flag- passed to import Log::Shiras::Switchboard did not pass the format test.";
83 }
84 }
85  
86 # Implement string stripping
87 2 ▶ if( @strip_list ){
Branch: 1 branch
BranchTrueFalseTotal
if (@strip_list) 2 0 2
88 2 $strip_match = '(' . join( '|', @strip_list ) . ')';
89 2 ▶ warn "Using Log::Shiras::Unhide-$VERSION strip_match string: $strip_match" if !$ENV{hide_warn};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"hide_warn"} 1 1 2
90 2 _resurrector_init();
91 2 $ENV{loaded_filter_util_call} = 1;
92 # Check for Filter::Util::Call availability
93 2 warn "Attempting to strip leading qr/###$Log::Shiras::Unhide::strip_match/" if IMPORT_DEBUG;
94 2 my $FILTER_MODULE = "Filter::Util::Call";
95 2 my $require_result;
96 2 eval{ $require_result = require_module( 'Filter::Util::Call' ) };# require_module( $FILTER_MODULE ) };#
97 2 ▶ if( $require_result and ($require_result == 1 or $require_result eq $FILTER_MODULE) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($require_result and $require_result == 1 || $require_result eq $FILTER_MODULE) { } 2 0 2
Condition33%2/6
$require_result and $require_result == 1 || $require_result eq $FILTER_MODULE
!ll&&!rl&&r
002
$require_result == 1 or $require_result eq $FILTER_MODULE
l!l&&r!l&&!r
200
MC/DC0%0/3
$require_result and $require_result == 1 || $require_result eq $FILTER_MODULE
$require_result $require_result == 1 $require_result eq $FILTER_MODULE
Truth table25%1/4
A and B or C
A= $require_resultB= $require_result == 1C= $require_result eq $FILTER_MODULE
ABCresult
0XX0
1000
11X1
1011
98 2 $ENV{loaded_filter_util_call} = 1;
99 # Strip the top level script
100 Filter::Util::Call::filter_add(
101 21 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
102 21 my $status;
103 21 ▶ if($status = Filter::Util::Call::filter_read() > 0 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($status = &Filter::Util::Call::filter_read() > 0) 20 1 21
104 20 s/^(\s*)###$Log::Shiras::Unhide::strip_match\s/$1/mg;
105 }
106 21 warn "----->script scrubbed line : $_" if VIEW_TRANSFORM;
107 21 $status;
108 }
109 2 );
110 }else{
111 0 warn "$FILTER_MODULE required to strip the script. The flags |" . join( ' ', @args ) .
112 "| will only be implemented for 'use'd modules - ('cpan Filter::Util::Call' to install)";
113 }
114 }
115 }
116  
117 #########1 Functional Startup Private Methods 5#########6#########7#########8#########9
118  
119 2 ▶sub _resurrector_init {
Subroutine _resurrector_init: called CC=1 SCAR=0.0
120 2 unshift @INC, \&_resurrector_loader;
121 }
122  
123 248 ▶sub _resurrector_loader {
Subroutine _resurrector_loader: called CC=5 SCAR=16.1
124  
125 248 my ($code, $module) = @_;
126  
127 248 warn "$module sent to source filter scrub\n" if INTERNAL_DEBUG;
128  
129 # Skip Stuff that isn't likely to have source filter flags
130 248 ▶ if($module =~ $my_unhide_skip_check) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module =~ /$my_unhide_skip_check/x) { } 173 75 248
131 173 warn "Don't scrub |$module| (it's on the skip list) return undef" if INTERNAL_DEBUG;
132 173 return undef;
133 }else{
134 75 warn "Scrubbing Module: $module\n" if INTERNAL_DEBUG;;
135 }
136  
137 75 my $path = $module;
138 75 warn "Finding the location of module: $module" if INTERNAL_DEBUG;
139  
140 # Skip unknown files
141 75 ▶ if(!-f $module) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $module) 75 0 75
142 # We might have a 'use lib' statement that modified the
143 # INC path, search again.
144 75 $path = _pm_search($module);
145 75 ▶ if(! defined $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path) 3 72 75
146 3 warn "File $module not found" if INTERNAL_DEBUG;
147 3 return undef;
148 }
149 72 warn "File $module found in $path" if INTERNAL_DEBUG;
150 }
151  
152 72 warn "Unhiding debug in module $path" if INTERNAL_DEBUG;
153 72 my $fh;
154 72 ▶ if( exists $run_once_hash->{$path} ){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $run_once_hash->{$path}) { } 0 72 72
155 0 warn "No action since this is already done" if INTERNAL_DEBUG;
156 }else{
157 72 $fh = _resurrector_fh($path);
158 72 $run_once_hash->{$path} = 1;
159 }
160  
161 72 my $abs_path = File::Spec->rel2abs( $path );
162 72 warn "Setting %INC entry of $module to $abs_path" if INTERNAL_DEBUG;
163 72 $INC{$module} = $abs_path;
164 72 eval 'use $module_copy';
165 72 return $fh;
166 }
167  
168 75 ▶sub _pm_search {
Subroutine _pm_search: called CC=4 SCAR=13.9
169  
170 75 my($pmfile) = @_;
171  
172 75 warn "Reviewing: $pmfile" if INTERNAL_DEBUG;
173 75 for(@INC) {
174 # Skip subrefs
175 683 warn "Next file: $_" if INTERNAL_DEBUG;
176 683 ▶ next if ref($_);
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ 75 608 683
177 608 warn "Passed the ref test..." if INTERNAL_DEBUG;
178 608 my $path = File::Spec->catfile($_, $pmfile);
179 608 ▶ return $path if -f $path;
Branch: 1 branch
BranchTrueFalseTotal
if -f $path 72 536 608
180 }
181  
182 3 return undef;
183 }
184  
185 72 ▶sub _resurrector_fh {
Subroutine _resurrector_fh: called CC=2 SCAR=6.9
186  
187 72 my( $file, ) = @_;
188 72 warn "Resurrecting lines from file: $file" if INTERNAL_DEBUG;
189 72 warn "with string: $strip_match" if INTERNAL_DEBUG;
190 72 ▶ open my $start_file_handle, "<$file" or die "Cannot open $file";
Branch: 1 branch
BranchTrueFalseTotal
open my $start_file_handle, "<$file" or die "Cannot open $file" 72 0 72
191 72 my $text;
192 {
193 # read the file
194 72 local($/) = undef;
195 72 $text = <$start_file_handle>;
196 72 warn "Read ", length($text), " bytes from $file" if INTERNAL_DEBUG;
197 }
198 72 close $start_file_handle;
199  
200 # Transform the file
201 72 $text =~ s/^(\s*)###$strip_match\s/$1/mg;
202 72 warn "----->script scrubbed file:\n$text" if VIEW_TRANSFORM;
203 72 warn "-------------------------------------------->Module Scrub complete" if INTERNAL_DEBUG;
204  
205 # Turn it back over to management by the INC loader via fh
206 72 my( $tmp_fh ) = File::Temp->new( UNLINK => 1, DIR => $temp_dir );# ( UNLINK => 1 );
207 72 print $tmp_fh $text;
208 72 seek $tmp_fh, 0, 0;
209  
210 72 return $tmp_fh;
211 }
212  
213 #########1 Phinish 3#########4#########5#########6#########7#########8#########9
214  
215 2 1;
216  
217 #########1 Documentation 3#########4#########5#########6#########7#########8#########9
218 __END__
« blib/lib/Log/Shiras/Report/Test2Diag.pm ↑ Summary lib/Log/Shiras/Report/MetaMessage.pm »