| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $file = $meta->{file}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return 0.85 if $file->{execute} && $file->{binary}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
$file->{"execute"} and $file->{"binary"}
$file->{"execute"} and $file->{"binary"}
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"}
Truth table0%0/3
A and B
A= $file->{"execute"}B= $file->{"binary"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | return 0.8 if $file->{lc_ext} eq '.bat'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | return 0.25 if $file->{execute}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | elsif ( $meta->{is_hash} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | return 0.9 if $src->raw->{exec}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | @command = @{ $source->raw->{exec} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition25%1/4
$source->raw->{'exec'} || []
$source->raw->{'exec'} || []
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'}
Truth table0%0/2
A
A= $source->raw->{'exec'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | elsif ( $meta->{is_scalar} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | @command = File::Spec->rel2abs( ${ $source->raw } ) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ${ $source->raw }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 || []
$source->test_args || []
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
Truth table0%0/2
A
A= $source->test_args
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||