Permalink
Browse files

Tidied

  • Loading branch information...
AndyA committed Jun 16, 2009
1 parent bb6664b commit 95a0c96368b7a3422aa2767e61a7a11e7b75b91b
View
@@ -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 );
@@ -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'}
@@ -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(@_); }
@@ -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');
View
@@ -70,7 +70,6 @@ sub _initialize {
return $self;
}
-
##############################################################################
=head3 C<can_handle>
@@ -104,7 +103,6 @@ sub can_handle {
return;
}
-
=head3 C<make_source>
I<Abstract method>. Takes a hashref as an argument:
@@ -136,7 +134,6 @@ sub make_source {
return;
}
-
##############################################################################
=head2 Instance Methods
@@ -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);
@@ -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} = [];
@@ -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;
@@ -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
@@ -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'
+ );
}
##############################################################################
@@ -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);
@@ -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;
@@ -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
@@ -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] } );
}
@@ -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;
@@ -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);
@@ -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};
@@ -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
@@ -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');
@@ -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';
@@ -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>
Oops, something went wrong.

0 comments on commit 95a0c96

Please sign in to comment.