requires 'Data::OptList' => '0';
requires 'List::MoreUtils' => '0.12';
requires 'Package::DeprecationManager' => '0.04';
+requires 'Params::Util' => '0';
requires 'Scalar::Util' => '1.19';
requires 'Sub::Exporter' => '0.980';
requires 'Sub::Name' => '0';
use warnings;
use List::Util ();
+use Params::Util ();
our $VERSION = '1.14';
$VERSION = eval $VERSION;
return $self->_inline_throw_error(
q{'The argument passed to first must be a code reference'})
- . q{if $_[0] && ( ref $_[0] || q{} ) ne 'CODE';};
+ . q{ unless Params::Util::_CODELIKE( $_[0] );};
}
sub _return_value {
use strict;
use warnings;
+use Params::Util ();
+
our $VERSION = '1.14';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
return $self->_inline_throw_error(
q{'The argument passed to grep must be a code reference'})
- . q{if $_[0] && ( ref $_[0] || q{} ) ne 'CODE';};
+ . q{ unless Params::Util::_CODELIKE( $_[0] );};
}
sub _return_value {
use strict;
use warnings;
+use Moose::Util ();
+
our $VERSION = '1.14';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
return $self->_inline_throw_error(
q{'The argument passed to join must be a string'})
- . ' unless defined $_[0] && ! ref $_[0];';
+ . ' unless Moose::Util::_STRINGLIKE( $_[0] );';
}
sub _return_value {
use strict;
use warnings;
+use Params::Util ();
+
our $VERSION = '1.14';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
return $self->_inline_throw_error(
q{'The argument passed to map must be a code reference'})
- . q{if $_[0] && ( ref $_[0] || q{} ) ne 'CODE';};
+ . q{ unless Params::Util::_CODELIKE( $_[0] );};
}
sub _return_value {
use strict;
use warnings;
-use List::MoreUtils;
+use List::MoreUtils ();
+use Params::Util ();
our $VERSION = '1.14';
$VERSION = eval $VERSION;
. ' unless defined $_[0] && $_[0] =~ /^\\d+$/;' . "\n"
. $self->_inline_throw_error(
q{'The second argument passed to natatime must be a code reference'})
- . q{ if defined $_[1] && ( ref $_[1] || q{} ) ne 'CODE';};
+ . q{ if @_ == 2 && ! Params::Util::_CODELIKE( $_[1] );};
}
sub _inline_return_value {
use warnings;
use List::Util ();
+use Params::Util ();
our $VERSION = '1.14';
$VERSION = eval $VERSION;
return $self->_inline_throw_error(
q{'The argument passed to reduce must be a code reference'})
- . q{if $_[0] && ( ref $_[0] || q{} ) ne 'CODE';};
+ . q{ unless Params::Util::_CODELIKE( $_[0] );};
}
sub _return_value {
use strict;
use warnings;
+use Params::Util ();
+
our $VERSION = '1.14';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
return $self->_inline_throw_error(
q{'The argument passed to sort must be a code reference'})
- . q{if $_[0] && ( ref $_[0] || q{} ) ne 'CODE';};
+ . q{ if @_ && ! Params::Util::_CODELIKE( $_[0] );};
}
sub _return_value {
use strict;
use warnings;
+use Params::Util ();
+
our $VERSION = '1.14';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
return $self->_inline_throw_error(
q{'The argument passed to sort_in_place must be a code reference'})
- . q{if $_[0] && ( ref $_[0] || q{} ) ne 'CODE';};
+ . q{ if @_ && ! Params::Util::_CODELIKE( $_[0] );};
}
sub _adds_members { 0 }
use strict;
use warnings;
+use Moose::Util ();
+use Params::Util ();
+
our $VERSION = '1.14';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
return $self->_inline_throw_error(
q{'The argument passed to match must be a string or regexp reference'}
- ) . q{ unless ! ref $_[0] || ref $_[0] eq 'Regexp';};
+ ) . q{ unless Moose::Util::_STRINGLIKE( $_[0] ) || Params::Util::_REGEX( $_[0] );};
}
sub _return_value {
use strict;
use warnings;
+use Moose::Util ();
+use Params::Util ();
+
our $VERSION = '1.14';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
return $self->_inline_throw_error(
q{'The first argument passed to replace must be a string or regexp reference'}
)
- . q{ unless ! ref $_[0] || ref $_[0] eq 'Regexp';} . "\n"
+ . q{ unless Moose::Util::_STRINGLIKE( $_[0] ) || Params::Util::_REGEX( $_[0] );}
. $self->_inline_throw_error(
q{'The second argument passed to replace must be a string or code reference'}
- ) . q{ unless ! ref $_[1] || ref $_[1] eq 'CODE';};
+ ) . q{ unless Moose::Util::_STRINGLIKE( $_[1] ) || Params::Util::_CODELIKE( $_[1] );};
}
sub _potential_value {
use strict;
use warnings;
+use Moose::Util ();
+
our $VERSION = '1.14';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
my $code
= $self->_inline_throw_error(
q{'The first argument passed to substr must be an integer'})
- . q{ if ref $offset || $offset !~ /^-?\\d+$/;} . "\n"
+ . q{ unless $offset =~ /^-?\\d+$/;} . "\n"
. $self->_inline_throw_error(
- q{'The second argument passed to substr must be a positive integer'})
- . q{ if ref $length || $offset !~ /^-?\\d+$/;};
+ q{'The second argument passed to substr must be an integer'})
+ . q{ unless $length =~ /^-?\\d+$/;};
if ($for_writer) {
$code
.= "\n"
. $self->_inline_throw_error(
q{'The third argument passed to substr must be a string'})
- . q{ unless defined $replacement && ! ref $replacement;};
+ . q{ unless Moose::Util::_STRINGLIKE($replacement);};
}
return $code;
use warnings;
use Data::OptList;
+use Params::Util qw( _STRING );
use Sub::Exporter;
use Scalar::Util 'blessed';
use Class::MOP 0.60;
_create_alias('Class', $to, $trait, $from);
}
+# XXX - this should be added to Params::Util
+sub _STRINGLIKE ($) {
+ return _STRING( $_[0] )
+ || ( blessed $_[0]
+ && overload::Method( $_[0], q{""} )
+ && length "$_[0]" );
+}
+
1;
__END__
}
{
+ package Overloader;
+
+ use overload
+ '&{}' => sub { ${ $_[0] } },
+ bool => sub {1};
+
+ sub new {
+ bless \$_[1], $_[0];
+ }
+}
+
+{
run_tests(build_class);
run_tests( build_class( lazy => 1, default => sub { [ 42, 84 ] } ) );
run_tests( build_class( trigger => sub { } ) );
qr/The argument passed to grep must be a code reference/,
'throws an error when passing a non coderef to grep';
+ my $overloader = Overloader->new( sub { $_ < 5 } );
+ is_deeply(
+ [ $obj->grep($overloader) ],
+ [ 2 .. 4 ],
+ 'grep works with obj that overload code dereferencing'
+ );
+
is_deeply(
[ $obj->grep_curried ],
[ 2 .. 4 ],
'substr throws an error when first argument is not an integer';
throws_ok { $obj->substr( 1, {} ) }
- qr/The second argument passed to substr must be a positive integer/,
- 'substr throws an error when second argument is not a positive integer';
+ qr/The second argument passed to substr must be an integer/,
+ 'substr throws an error when second argument is not an integer';
throws_ok { $obj->substr( 1, 2, {} ) }
qr/The third argument passed to substr must be a string/,