Skip to content

Commit

Permalink
Remove lazy proxy subs
Browse files Browse the repository at this point in the history
  • Loading branch information
kentfredric committed Apr 5, 2014
1 parent 2a9f871 commit d632af6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
34 changes: 15 additions & 19 deletions lib/Path/ScanINC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,12 @@ For more details, see L<< C<perldoc perlfunc> or C<perldoc -f require> |perlfunc
# Sub Lazy-Aliases
use subs 'inc';
use Class::Tiny qw(inc immutable);
use Try::Tiny qw( try catch );
use Scalar::Util qw( blessed reftype );
use Carp qw( croak );
use Path::Tiny qw( path );

## no critic (ProhibitSubroutinePrototypes)
sub __try(&;@) { require Try::Tiny; goto \&Try::Tiny::try; }
sub __catch(&;@) { require Try::Tiny; goto \&Try::Tiny::catch; }
sub __blessed($) { require Scalar::Util; goto \&Scalar::Util::blessed; }
sub __reftype($) { require Scalar::Util; goto \&Scalar::Util::reftype; }
## use critic
sub __pp { require Data::Dump; goto \&Data::Dump::pp; }
sub __croak { require Carp; goto \&Carp::croak; }
sub __path { require Path::Tiny; goto \&Path::Tiny::path; }
sub __pp { require Data::Dump; goto \&Data::Dump::pp; }
## no critic (RequireArgUnpacking)
sub __croakf { require Carp; @_ = ( sprintf $_[0], splice @_, 1 ); goto \&Carp::croak; }
## use critic
Expand All @@ -119,7 +115,7 @@ sub _bad_param {
my ( $obj, $name, $expected, $got ) = @_;
my $format =
qq[Initialization parameter '%s' to \$object->new( ) ( %s->new() ) expects %s.\n] . qq[\tYou gave \$object->new( %s => %s )];
return __croakf( $format, $name, __blessed($obj), $expected, $name, __pp($got) );
return __croakf( $format, $name, blessed($obj), $expected, $name, __pp($got) );
}

sub _fix_immutable {
Expand All @@ -135,7 +131,7 @@ sub _fix_inc {
my ($self) = @_;
if ( exists $self->{inc} ) {
return $self->_bad_param( 'inc', 'an array-reference', $self->{inc} )
if not __try { my $i = $self->{inc}->[0]; 1 } __catch { undef };
if not try { my $i = $self->{inc}->[0]; 1 } catch { undef };
}
if ( $self->immutable ) {
if ( exists $self->{inc} ) {
Expand Down Expand Up @@ -215,21 +211,21 @@ sub _ref_expand {
my ( $self, $ref, @query ) = @_;

# See perldoc perlfunc / require
if ( __blessed($ref) ) {
if ( blessed($ref) ) {
my (@result) = $ref->INC( $self->_pm_inc_path(@query) );
if ( not @result ) {
return [ undef, ];
}
return [ 1, @result ];
}
if ( __reftype($ref) eq 'CODE' ) {
if ( reftype($ref) eq 'CODE' ) {
my (@result) = $ref->( $ref, $self->_pm_inc_path(@query) );
if ( not @result ) {
return [ undef, ];
}
return [ 1, @result ];
}
if ( __reftype($ref) eq 'ARRAY' ) {
if ( reftype($ref) eq 'ARRAY' ) {
my $code = $ref->[0];
my (@result) = $code->( $ref, $self->_pm_inc_path(@query) );
if ( not @result ) {
Expand All @@ -239,7 +235,7 @@ sub _ref_expand {
}
## no critic (RequireInterpolationOfMetachars)

__croakf( 'Unknown type of ref in @INC not supported: %s', __reftype($ref) );
__croakf( 'Unknown type of ref in @INC not supported: %s', reftype($ref) );
return [ undef, ];
}

Expand Down Expand Up @@ -309,7 +305,7 @@ sub first_file {
}
next;
}
my $fullpath = __path($path)->child(@args);
my $fullpath = path($path)->child(@args);
if ( -e $fullpath and -f $fullpath ) {
return $fullpath;
}
Expand Down Expand Up @@ -363,7 +359,7 @@ sub all_files {
}
next;
}
my $fullpath = __path($path)->child(@args);
my $fullpath = path($path)->child(@args);
if ( -e $fullpath and -f $fullpath ) {
push @out, $fullpath;
}
Expand All @@ -389,7 +385,7 @@ sub first_dir {
}
next;
}
my $fullpath = __path($path)->child(@args);
my $fullpath = path($path)->child(@args);
if ( -e $fullpath and -d $fullpath ) {
return $fullpath;
}
Expand All @@ -415,7 +411,7 @@ sub all_dirs {
}
next;
}
my $fullpath = __path($path)->child(@args);
my $fullpath = path($path)->child(@args);
if ( -e $fullpath and -d $fullpath ) {
push @out, $fullpath;
}
Expand Down
12 changes: 12 additions & 0 deletions t/04_internals.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use winfail;

use_ok('Path::ScanINC');

=begin comment
subtest __try => sub {
will_win 'exceptions not fatal to caller';
t { Path::ScanINC::__try( sub { die 'not a problem' } ) };
Expand Down Expand Up @@ -48,6 +50,10 @@ subtest __reftype => sub {
};
=end comment
=cut

subtest __pp => sub {
will_win 'pp loads ok';

Expand All @@ -58,13 +64,19 @@ subtest __pp => sub {
is( $gotdump, '[]', '__pp resolves ok' );
};

=begin comment
subtest __croak => sub {
will_fail 'croak loads ok ';
t { Path::ScanINC::__croak("its ok") };
};
=end comment
=cut

subtest __croakf => sub {
will_fail 'basic croakf';
t { Path::ScanINC::__croakf('test') };
Expand Down

0 comments on commit d632af6

Please sign in to comment.