blib/lib/TAP/Parser/SourceHandler/Executable.pm

filter: Statementstmt 64.2% 54 / 84 Branchbran 43.1% 19 / 44 Conditioncond 35.7% 5 / 14 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 76.9% 10 / 13 Podpod 100% 4 / 4 totaltotal 55.6% 93 / 167 CC 29 SCAR 26.9
CC
29
Cov
55%
can_handle
19.4
can_handle
19.4
make_iterator
17.7
CRAP 14.7
« blib/lib/App/Prove.pm ↑ Summary blib/lib/TAP/Formatter/Console/Session.pm »
1 package TAP::Parser::SourceHandler::Executable;
2  
3 37 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 37 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 37 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 37 ▶use TAP::Parser::IteratorFactory ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 37 ▶use TAP::Parser::Iterator::Process ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 37 ▶use base 'TAP::Parser::SourceHandler';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 37 TAP::Parser::IteratorFactory->register_handler(__PACKAGE__);
14  
15 =head1 NAME
16  
17 TAP::Parser::SourceHandler::Executable - Stream output from an executable TAP source
18  
19 =head1 VERSION
20  
21 Version 3.52
22  
23 =cut
24  
25 37 our $VERSION = '3.52';
26  
27 =head1 SYNOPSIS
28  
29 use TAP::Parser::Source;
30 use TAP::Parser::SourceHandler::Executable;
31  
32 my $source = TAP::Parser::Source->new->raw(['/usr/bin/ruby', 'mytest.rb']);
33 $source->assemble_meta;
34  
35 my $class = 'TAP::Parser::SourceHandler::Executable';
36 my $vote = $class->can_handle( $source );
37 my $iter = $class->make_iterator( $source );
38  
39 =head1 DESCRIPTION
40  
41 This is an I<executable> L<TAP::Parser::SourceHandler> - it has 2 jobs:
42  
43 1. Figure out if the L<TAP::Parser::Source> it's given is an executable
44 command (L</can_handle>).
45  
46 2. Creates an iterator for executable commands (L</make_iterator>).
47  
48 Unless you're writing a plugin or subclassing L<TAP::Parser>, you
49 probably won't need to use this module directly.
50  
51 =head1 METHODS
52  
53 =head2 Class Methods
54  
55 =head3 C<can_handle>
56  
57 my $vote = $class->can_handle( $source );
58  
59 Only votes if $source looks like an executable file. Casts the
60 following votes:
61  
62 0.9 if it's a hash with an 'exec' key
63 0.8 if it's a .bat file
64 0.75 if it's got an execute bit set
65  
66 =cut
67  
68 307 ▶sub can_handle {
Subroutine can_handle: called CC=8 SCAR=29.6
Pod documented
69 0 ▶ my ( $class, $src ) = @_;
Subroutine can_handle: not called CC=8 SCAR=29.6
Pod documented
70 0 my $meta = $src->meta;
71  
72 0 ▶ if ( $meta->{is_file} ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($meta->{'is_file'}) { } 221 86 307
elsif ($meta->{'is_hash'}) { } 12 74 86
if ($meta->{'is_file'}) { } 0 0 0
elsif ($meta->{'is_hash'}) { } 0 0 0
73 0 my $file = $meta->{file};
74  
75 0 ▶ return 0.85 if $file->{execute} && $file->{binary};
Branch: 2 branches
BranchTrueFalseTotal
if $file->{"execute"} and $file->{"binary"} 0 221 221
if $file->{"execute"} and $file->{"binary"} 0 0 0
Condition33%2/6
$file->{"execute"} and $file->{"binary"}
!ll&&!rl&&r
21740
$file->{"execute"} and $file->{"binary"}
!ll&&!rl&&r
000
MC/DC0%0/2
$file->{"execute"} and $file->{"binary"}
$file->{"execute"} $file->{"binary"}
MC/DC0%0/2
$file->{"execute"} and $file->{"binary"}
$file->{"execute"} $file->{"binary"}
Truth table66%2/3
A and B
A= $file->{"execute"}B= $file->{"binary"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $file->{"execute"}B= $file->{"binary"}
ABresult
0X0
100
111
76 0 ▶ return 0.8 if $file->{lc_ext} eq '.bat';
Branch: 2 branches
BranchTrueFalseTotal
if $file->{"lc_ext"} eq ".bat" 2 219 221
if $file->{"lc_ext"} eq ".bat" 0 0 0
77 0 ▶ return 0.25 if $file->{execute};
Branch: 2 branches
BranchTrueFalseTotal
if $file->{"execute"} 4 215 219
if $file->{"execute"} 0 0 0
78 }
79 elsif ( $meta->{is_hash} ) {
80 0 ▶ return 0.9 if $src->raw->{exec};
Branch: 2 branches
BranchTrueFalseTotal
if $src->raw->{"exec"} 12 0 12
if $src->raw->{"exec"} 0 0 0
81 }
82  
83 0 return 0;
84 }
85  
86 =head3 C<make_iterator>
87  
88 my $iterator = $class->make_iterator( $source );
89  
90 Returns a new L<TAP::Parser::Iterator::Process> for the source.
91 C<$source-E<gt>raw> must be in one of the following forms:
92  
93 { exec => [ @exec ] }
94  
95 [ @exec ]
96  
97 $file
98  
99 C<croak>s on error.
100  
101 =cut
102  
103 15 ▶sub make_iterator {
Subroutine make_iterator: called CC=8 SCAR=28.7
Pod documented
104 0 ▶ my ( $class, $source ) = @_;
Subroutine make_iterator: not called CC=8 SCAR=28.7
Pod documented
105 0 my $meta = $source->meta;
106  
107 0 my @command;
108 0 ▶ if ( $meta->{is_hash} ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($meta->{'is_hash'}) { } 11 4 15
elsif ($meta->{'is_scalar'}) { } 1 3 4
elsif ($meta->{'is_array'}) { } 1 2 3
if ($meta->{'is_hash'}) { } 0 0 0
elsif ($meta->{'is_scalar'}) { } 0 0 0
elsif ($meta->{'is_array'}) { } 0 0 0
109 0 ▶ @command = @{ $source->raw->{exec} || [] };
Condition25%1/4
$source->raw->{'exec'} || []
l!l
110
$source->raw->{'exec'} || []
l!l
00
MC/DC0%0/1
$source->raw->{'exec'} || []
$source->raw->{'exec'}
MC/DC0%0/1
$source->raw->{'exec'} || []
$source->raw->{'exec'}
Truth table50%1/2
A
A= $source->raw->{'exec'}
Aresult
11
00
Truth table0%0/2
A
A= $source->raw->{'exec'}
Aresult
11
00
110 }
111 elsif ( $meta->{is_scalar} ) {
112 0 @command = File::Spec->rel2abs( ${ $source->raw } )
113 0 ▶ if ${ $source->raw };
Branch: 2 branches
BranchTrueFalseTotal
if ${$source->raw;} 1 0 1
if ${$source->raw;} 0 0 0
114 }
115 elsif ( $meta->{is_array} ) {
116 0 @command = @{ $source->raw };
117 }
118  
119 0 ▶ $class->_croak('No command found in $source->raw!') unless @command;
Branch: 2 branches
BranchTrueFalseTotal
unless @command 2 13 15
unless @command 0 0 0
120  
121 0 $class->_autoflush( \*STDOUT );
122 0 $class->_autoflush( \*STDERR );
123  
124 0 ▶ push @command, @{ $source->test_args || [] };
Condition50%2/4
$source->test_args || []
l!l
112
$source->test_args || []
l!l
00
MC/DC100%1/1
$source->test_args || []
$source->test_args
MC/DC0%0/1
$source->test_args || []
$source->test_args
Truth table100%2/2
A
A= $source->test_args
Aresult
11
00
Truth table0%0/2
A
A= $source->test_args
Aresult
11
00
125  
126 0 return $class->iterator_class->new(
127 { command => \@command,
128 merge => $source->merge
129 }
130 );
131 }
132  
133 =head3 C<iterator_class>
134  
135 The class of iterator to use, override if you're sub-classing. Defaults
136 to L<TAP::Parser::Iterator::Process>.
137  
138 =cut
139  
140 37 ▶use constant iterator_class => 'TAP::Parser::Iterator::Process';
Subroutine BEGIN: called CC=1 SCAR=0.0
141  
142 # Turns on autoflush for the handle passed
143 444 ▶sub _autoflush {
Subroutine _autoflush: called CC=1 SCAR=1.2
144 0 ▶ my ( $class, $flushed ) = @_;
Subroutine _autoflush: not called CC=1 SCAR=1.2
145 0 my $old_fh = select $flushed;
146 0 $| = 1;
147 0 select $old_fh;
148 }
149  
150 37 1;
151  
152 =head1 SUBCLASSING
153  
154 Please see L<TAP::Parser/SUBCLASSING> for a subclassing overview.
155  
156 =head2 Example
157  
158 package MyRubySourceHandler;
159  
160 use strict;
161  
162 use Carp qw( croak );
163 use TAP::Parser::SourceHandler::Executable;
164  
165 use base 'TAP::Parser::SourceHandler::Executable';
166  
167 # expect $handler->(['mytest.rb', 'cmdline', 'args']);
168 sub make_iterator {
169 my ($self, $source) = @_;
170 my @test_args = @{ $source->test_args };
171 my $rb_file = $test_args[0];
172 croak("error: Ruby file '$rb_file' not found!") unless (-f $rb_file);
173 return $self->SUPER::raw_source(['/usr/bin/ruby', @test_args]);
174 }
175  
176 =head1 SEE ALSO
177  
178 L<TAP::Object>,
179 L<TAP::Parser>,
180 L<TAP::Parser::IteratorFactory>,
181 L<TAP::Parser::SourceHandler>,
182 L<TAP::Parser::SourceHandler::Perl>,
183 L<TAP::Parser::SourceHandler::File>,
184 L<TAP::Parser::SourceHandler::Handle>,
185 L<TAP::Parser::SourceHandler::RawTAP>
186  
187 =cut
« blib/lib/App/Prove.pm ↑ Summary blib/lib/TAP/Formatter/Console/Session.pm »