Skip to content

Commit

Permalink
Tidied
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyA committed Jun 16, 2009
1 parent bb6664b commit 95a0c96
Show file tree
Hide file tree
Showing 16 changed files with 366 additions and 346 deletions.
77 changes: 40 additions & 37 deletions lib/TAP/Parser.pm
Expand Up @@ -3,18 +3,18 @@ package TAP::Parser;
use strict;
use vars qw($VERSION @ISA);

use TAP::Base ();
use TAP::Parser::Grammar ();
use TAP::Parser::Result ();
use TAP::Parser::ResultFactory ();
use TAP::Parser::Source::Executable ();
use TAP::Parser::Source::Perl ();
use TAP::Parser::Source::File ();
use TAP::Parser::Source::RawTAP ();
use TAP::Parser::Source::Handle ();
use TAP::Parser::Iterator ();
use TAP::Parser::IteratorFactory ();
use TAP::Parser::SourceFactory ();
use TAP::Base ();
use TAP::Parser::Grammar ();
use TAP::Parser::Result ();
use TAP::Parser::ResultFactory ();
use TAP::Parser::Source::Executable ();
use TAP::Parser::Source::Perl ();
use TAP::Parser::Source::File ();
use TAP::Parser::Source::RawTAP ();
use TAP::Parser::Source::Handle ();
use TAP::Parser::Iterator ();
use TAP::Parser::IteratorFactory ();
use TAP::Parser::SourceFactory ();

use Carp qw( confess );

Expand Down Expand Up @@ -293,8 +293,8 @@ L<TAP::Parser::SourceFactory>.
# new() implementation supplied by TAP::Base

# This should make overriding behaviour of the Parser in subclasses easier:
sub _default_source_class {'TAP::Parser::Source::Executable'} # deprecated
sub _default_perl_source_class {'TAP::Parser::Source::Perl'} # deprecated
sub _default_source_class {'TAP::Parser::Source::Executable'} # deprecated
sub _default_perl_source_class {'TAP::Parser::Source::Perl'} # deprecated
sub _default_grammar_class {'TAP::Parser::Grammar'}
sub _default_iterator_factory_class {'TAP::Parser::IteratorFactory'}
sub _default_result_factory_class {'TAP::Parser::ResultFactory'}
Expand Down Expand Up @@ -397,10 +397,10 @@ C<source_factory_class> can be customized, as described in L</new>.
=cut

# This should make overriding behaviour of the Parser in subclasses easier:
sub make_source { shift->source_class->new(@_); } # deprecated
sub make_perl_source { shift->perl_source_class->new(@_); } # deprecated
sub make_source { shift->source_class->new(@_); } # deprecated
sub make_perl_source { shift->perl_source_class->new(@_); } # deprecated
sub make_source_factory { shift->source_factory_class->new(@_); }
sub make_grammar { shift->grammar_class->new(@_); }
sub make_grammar { shift->grammar_class->new(@_); }
sub make_iterator { shift->iterator_factory_class->make_iterator(@_); }
sub make_result { shift->result_factory_class->make_result(@_); }

Expand Down Expand Up @@ -487,29 +487,32 @@ sub make_result { shift->result_factory_class->make_result(@_); }
$self->_croak("Unknown options: @excess");
}

# convert $tap & $exec to $raw_source equiv.
my $raw_source_ref;
# convert $tap & $exec to $raw_source equiv.
my $raw_source_ref;
if ($tap) {
$raw_source_ref = \$tap;
} elsif ($exec) {
$raw_source_ref = { exec => [ @$exec, @$test_args ] };
} elsif ($raw_source) {
$raw_source_ref = ref( $raw_source ) ? $raw_source : \$raw_source;
$raw_source_ref = \$tap;
}
elsif ($exec) {
$raw_source_ref = { exec => [ @$exec, @$test_args ] };
}
elsif ($raw_source) {
$raw_source_ref = ref($raw_source) ? $raw_source : \$raw_source;
}

if ($raw_source_ref) {
my $src_factory = $self->make_source_factory($sources);
my $source = $src_factory->make_source(
{ raw_source_ref => $raw_source_ref,
merge => $merge,
switches => $switches,
test_args => $test_args
}
);

if ($raw_source_ref) {
my $src_factory = $self->make_source_factory( $sources );
my $source = $src_factory->make_source({
raw_source_ref => $raw_source_ref,
merge => $merge,
switches => $switches,
test_args => $test_args
});

# TODO: replace this with something like:
# my $stream = $source->get_stream; # notice no "( $self )"
$stream = $source->get_stream($self);
}
# TODO: replace this with something like:
# my $stream = $source->get_stream; # notice no "( $self )"
$stream = $source->get_stream($self);
}

unless ($stream) {
$self->_croak('PANIC: could not determine stream');
Expand Down
3 changes: 0 additions & 3 deletions lib/TAP/Parser/Source.pm
Expand Up @@ -70,7 +70,6 @@ sub _initialize {
return $self;
}


##############################################################################

=head3 C<can_handle>
Expand Down Expand Up @@ -104,7 +103,6 @@ sub can_handle {
return;
}


=head3 C<make_source>
I<Abstract method>. Takes a hashref as an argument:
Expand Down Expand Up @@ -136,7 +134,6 @@ sub make_source {
return;
}


##############################################################################

=head2 Instance Methods
Expand Down
61 changes: 34 additions & 27 deletions lib/TAP/Parser/Source/Executable.pm
Expand Up @@ -3,8 +3,8 @@ package TAP::Parser::Source::Executable;
use strict;
use vars qw($VERSION @ISA);

use TAP::Parser::Source ();
use TAP::Parser::SourceFactory ();
use TAP::Parser::Source ();
use TAP::Parser::SourceFactory ();
use TAP::Parser::IteratorFactory ();

@ISA = qw(TAP::Parser::Source);
Expand Down Expand Up @@ -60,7 +60,7 @@ Returns a new C<TAP::Parser::Source::Executable> object.

sub _initialize {
my ( $self, @args ) = @_;
$self->SUPER::_initialize( @args );
$self->SUPER::_initialize(@args);

# TODO: move this to Perl sub-class - not used here?
$self->{switches} = [];
Expand All @@ -75,14 +75,16 @@ sub _initialize {
sub can_handle {
my ( $class, $raw_source_ref, $meta ) = @_;

if ($meta->{is_file}) {
my $file = $meta->{file};
# Note: we go in low so we can be out-voted
return 0.8 if $file->{lc_ext} eq '.sh';
return 0.8 if $file->{lc_ext} eq '.bat';
return 0.7 if $file->{execute};
} elsif ($meta->{hash}) {
return 0.99 if $raw_source_ref->{exec};
if ( $meta->{is_file} ) {
my $file = $meta->{file};

# Note: we go in low so we can be out-voted
return 0.8 if $file->{lc_ext} eq '.sh';
return 0.8 if $file->{lc_ext} eq '.bat';
return 0.7 if $file->{execute};
}
elsif ( $meta->{hash} ) {
return 0.99 if $raw_source_ref->{exec};
}

return 0;
Expand All @@ -91,23 +93,24 @@ sub can_handle {
sub make_source {
my ( $class, $args ) = @_;
my $raw_source_ref = $args->{raw_source_ref};
my $meta = $args->{meta};
my $source = $class->new;
my $meta = $args->{meta};
my $source = $class->new;

$source->merge( $args->{merge} );

if ($meta->{hash}) {
$source->raw_source( $raw_source_ref->{exec} );
} elsif ($meta->{is_file}) {
$source->raw_source([ $raw_source_ref ]);
} else {
$source->raw_source( $raw_source_ref );
if ( $meta->{hash} ) {
$source->raw_source( $raw_source_ref->{exec} );
}
elsif ( $meta->{is_file} ) {
$source->raw_source( [$raw_source_ref] );
}
else {
$source->raw_source($raw_source_ref);
}

return $source;
}


##############################################################################

=head2 Instance Methods
Expand All @@ -133,16 +136,20 @@ sub raw_source {
return $self->SUPER::raw_source unless @_;

my $ref = ref $_[0];
if (! defined( $ref )) {
; # fall through
} elsif ($ref eq 'ARRAY') {
if ( !defined($ref) ) {
; # fall through
}
elsif ( $ref eq 'ARRAY' ) {
return $self->SUPER::raw_source( $_[0] );
} elsif ($ref eq 'HASH') {
my $exec = $_[0]->{exec};
return $self->SUPER::raw_source( $exec );
}
elsif ( $ref eq 'HASH' ) {
my $exec = $_[0]->{exec};
return $self->SUPER::raw_source($exec);
}

$self->_croak('Argument to &raw_source must be an array reference or hash reference');
$self->_croak(
'Argument to &raw_source must be an array reference or hash reference'
);
}

##############################################################################
Expand Down
22 changes: 11 additions & 11 deletions lib/TAP/Parser/Source/File.pm
Expand Up @@ -3,8 +3,8 @@ package TAP::Parser::Source::File;
use strict;
use vars qw($VERSION @ISA);

use TAP::Parser::Source ();
use TAP::Parser::SourceFactory ();
use TAP::Parser::Source ();
use TAP::Parser::SourceFactory ();
use TAP::Parser::IteratorFactory ();

@ISA = qw(TAP::Parser::Source);
Expand Down Expand Up @@ -62,8 +62,8 @@ sub can_handle {
my $file = $meta->{file};
return 1 if $file->{lc_ext} eq '.tap';

if (my $exts = $config->{extensions}) {
return 1 if grep {lc($_) eq $file->{lc_ext}} @$exts;
if ( my $exts = $config->{extensions} ) {
return 1 if grep { lc($_) eq $file->{lc_ext} } @$exts;
}

return 0;
Expand All @@ -72,12 +72,11 @@ sub can_handle {
sub make_source {
my ( $class, $args ) = @_;
my $raw_source_ref = $args->{raw_source_ref};
my $source = $class->new;
$source->raw_source( $raw_source_ref );
my $source = $class->new;
$source->raw_source($raw_source_ref);
return $source;
}


##############################################################################

=head2 Instance Methods
Expand All @@ -96,9 +95,10 @@ sub raw_source {
return $self->SUPER::raw_source unless @_;

my $ref = ref $_[0];
if (! defined( $ref )) {
if ( !defined($ref) ) {
return $self->SUPER::raw_source( $_[0] );
} elsif ($ref eq 'SCALAR') {
}
elsif ( $ref eq 'SCALAR' ) {
return $self->SUPER::raw_source( ${ $_[0] } );
}

Expand All @@ -120,8 +120,8 @@ sub get_stream {
my $file = $self->raw_source;
my $fh;
open( $fh, '<', $file )
or $self->_croak( "error opening TAP source file '$file': $!" );
return $factory->make_iterator( $fh );
or $self->_croak("error opening TAP source file '$file': $!");
return $factory->make_iterator($fh);
}

1;
Expand Down
23 changes: 12 additions & 11 deletions lib/TAP/Parser/Source/Handle.pm
Expand Up @@ -3,8 +3,8 @@ package TAP::Parser::Source::Handle;
use strict;
use vars qw($VERSION @ISA);

use TAP::Parser::Source ();
use TAP::Parser::SourceFactory ();
use TAP::Parser::Source ();
use TAP::Parser::SourceFactory ();
use TAP::Parser::IteratorFactory ();

@ISA = qw(TAP::Parser::Source);
Expand Down Expand Up @@ -59,8 +59,9 @@ Returns a new C<TAP::Parser::Source::Handle> object.
sub can_handle {
my ( $class, $raw_source_ref, $meta ) = @_;

return 0.9 if $meta->{is_object}
&& UNIVERSAL::isa( $raw_source_ref, 'IO::Handle' );
return 0.9
if $meta->{is_object}
&& UNIVERSAL::isa( $raw_source_ref, 'IO::Handle' );

return 0.8 if $meta->{glob};

Expand All @@ -70,12 +71,11 @@ sub can_handle {
sub make_source {
my ( $class, $args ) = @_;
my $raw_source_ref = $args->{raw_source_ref};
my $source = $class->new;
$source->raw_source( $raw_source_ref );
my $source = $class->new;
$source->raw_source($raw_source_ref);
return $source;
}


##############################################################################

=head2 Instance Methods
Expand All @@ -95,10 +95,11 @@ sub raw_source {
return $self->SUPER::raw_source unless @_;

my $ref = ref $_[0];
if (! defined( $ref )) {
; # fall through
} elsif ($ref eq 'GLOB' || UNIVERSAL::isa( $ref, 'IO::Handle' )) {
return $self->SUPER::raw_source( shift );
if ( !defined($ref) ) {
; # fall through
}
elsif ( $ref eq 'GLOB' || UNIVERSAL::isa( $ref, 'IO::Handle' ) ) {
return $self->SUPER::raw_source(shift);
}

$self->_croak('Argument to &source must be a glob ref or an IO::Handle');
Expand Down
7 changes: 3 additions & 4 deletions lib/TAP/Parser/Source/Perl.pm
Expand Up @@ -8,7 +8,7 @@ use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ );
use constant IS_VMS => ( $^O eq 'VMS' );

use TAP::Parser::Source::Executable ();
use TAP::Parser::SourceFactory ();
use TAP::Parser::SourceFactory ();
use TAP::Parser::Utils qw( split_shell );

@ISA = 'TAP::Parser::Source::Executable';
Expand Down Expand Up @@ -80,15 +80,14 @@ sub make_source {
my $perl_script = $$raw_source_ref;
my $test_args = $args->{test_args} || [];

my $source = $class->new( $raw_source_ref );
my $source = $class->new($raw_source_ref);
$source->merge( $args->{merge} );
$source->switches( $args->{switches} ) if $args->{switches};
$source->raw_source([ $perl_script, @$test_args ]);
$source->raw_source( [ $perl_script, @$test_args ] );

return $source;
}


=head2 Instance Methods
=head3 C<raw_source>
Expand Down

0 comments on commit 95a0c96

Please sign in to comment.