view release on metacpan or search on metacpan
local/lib/perl5/Specio.pm view on Meta::CPAN
=back
=head1 OPTIONAL PREREQS
There are several optional prereqs that if installed will make this
distribution better in some way.
=over 4
=item * L<Ref::Util>
Installing this will speed up a number of type checks for built-in types.
=item * L<XString>
If this is installed it will be loaded instead of the L<B> module if you have
Perl 5.10 or greater. This module is much more memory efficient than loading
all of L<B>.
=item * L<Sub::Util> or L<Sub::Name>
local/lib/perl5/Specio/Library/Builtins.pm view on Meta::CPAN
use overload ();
use re ();
use Scalar::Util ();
use Specio::Constraint::Parameterizable;
use Specio::Declare;
use Specio::Helpers ();
BEGIN {
local $@ = undef;
my $has_ref_util
= eval { require Ref::Util; Ref::Util->VERSION('0.112'); 1 };
sub _HAS_REF_UTIL () {$has_ref_util}
}
declare(
'Item',
inline => sub {'1'}
);
declare(
'Undef',
local/lib/perl5/Specio/Library/Builtins.pm view on Meta::CPAN
&& do { ( my $val2 = %s + 0 ) =~ /\A-?[0-9]+(?:[Ee]\+?[0-9]+)?\z/ }
)
)
EOF
}
);
{
my $ref_check
= _HAS_REF_UTIL
? 'Ref::Util::is_plain_coderef(%s)'
: q{ref(%s) eq 'CODE'};
declare(
'CodeRef',
parent => t('Ref'),
inline => sub {
return sprintf( <<"EOF", ( $_[1] ) x 3 );
(
$ref_check
||
local/lib/perl5/Specio/Library/Builtins.pm view on Meta::CPAN
unless ( exists &re::is_regexp || _HAS_REF_UTIL ) {
require B;
*re::is_regexp = sub {
## no critic (ErrorHandling::RequireCheckingReturnValueOfEval)
eval { B::svref_2object( $_[0] )->MAGIC->TYPE eq 'r' };
};
}
my $ref_check
= _HAS_REF_UTIL
? 'Ref::Util::is_regexpref(%s)'
: 're::is_regexp(%s)';
declare(
'RegexpRef',
parent => t('Ref'),
inline => sub {
return sprintf( <<"EOF", ( $_[1] ) x 3 );
(
$ref_check
||
local/lib/perl5/Specio/Library/Builtins.pm view on Meta::CPAN
)
)
EOF
},
);
}
{
my $ref_check
= _HAS_REF_UTIL
? 'Ref::Util::is_plain_globref(%s)'
: q{ref( %s ) eq 'GLOB'};
declare(
'GlobRef',
parent => t('Ref'),
inline => sub {
return sprintf( <<"EOF", ( $_[1] ) x 3 );
(
$ref_check
||
local/lib/perl5/Specio/Library/Builtins.pm view on Meta::CPAN
)
)
EOF
}
);
}
{
my $ref_check
= _HAS_REF_UTIL
? 'Ref::Util::is_plain_globref(%s)'
: q{ref( %s ) eq 'GLOB'};
# NOTE: scalar filehandles are GLOB refs, but a GLOB ref is not always a
# filehandle
declare(
'FileHandle',
parent => t('Ref'),
inline => sub {
return sprintf( <<"EOF", ( $_[1] ) x 6 );
(
local/lib/perl5/Specio/Library/Builtins.pm view on Meta::CPAN
)
)
EOF
}
);
}
{
my $ref_check
= _HAS_REF_UTIL
? 'Ref::Util::is_blessed_ref(%s)'
: 'Scalar::Util::blessed(%s)';
declare(
'Object',
parent => t('Ref'),
inline => sub { sprintf( $ref_check, $_[1] ) },
);
}
declare(
local/lib/perl5/Specio/Library/Builtins.pm view on Meta::CPAN
&& length "%s"
&& Specio::Helpers::is_class_loaded( "%s" )
)
EOF
},
);
{
my $ref_check
= _HAS_REF_UTIL
? 'Ref::Util::is_plain_scalarref(%s) || Ref::Util::is_plain_refref(%s)'
: q{ref( %s ) eq 'SCALAR' || ref( %s ) eq 'REF'};
my $base_scalarref_check = sub {
return sprintf( <<"EOF", ( $_[0] ) x 4 );
(
(
$ref_check
)
||
(
local/lib/perl5/Specio/Library/Builtins.pm view on Meta::CPAN
$base_scalarref_check->($val),
$parameter->inline_check( '${' . $val . '}' ),
);
}
);
}
{
my $ref_check
= _HAS_REF_UTIL
? 'Ref::Util::is_plain_arrayref(%s)'
: q{ref( %s ) eq 'ARRAY'};
my $base_arrayref_check = sub {
return sprintf( <<"EOF", ( $_[0] ) x 3 );
(
$ref_check
||
(
Scalar::Util::blessed( %s )
&& defined overload::Method( %s, '\@{}' )
local/lib/perl5/Specio/Library/Builtins.pm view on Meta::CPAN
$parameter->inline_check('$_'),
$val,
);
}
);
}
{
my $ref_check
= _HAS_REF_UTIL
? 'Ref::Util::is_plain_hashref(%s)'
: q{ref( %s ) eq 'HASH'};
my $base_hashref_check = sub {
return sprintf( <<"EOF", ( $_[0] ) x 3 );
(
$ref_check
||
(
Scalar::Util::blessed( %s )
&& defined overload::Method( %s, '%%{}' )
local/lib/perl5/Type/Tiny/Manual/Optimization.pod view on Meta::CPAN
The simplest thing you can do to increase performance of many of
the built-in type constraints is to install L<Type::Tiny::XS>, a
set of ultra-fast type constraint checks implemented in C.
L<Type::Tiny> will attempt to load L<Type::Tiny::XS> and use its
type checks. If L<Type::Tiny::XS> is not available, it will then
try to use L<Mouse> I<< if it is already loaded >>, but Type::Tiny
won't attempt to load Mouse for you.
Certain type constraints can also be accelerated if you have
L<Ref::Util::XS> installed.
=head3 Types that can be accelerated by Type::Tiny::XS
The following simple type constraints from L<Types::Standard> will
be accelerated by Type::Tiny::XS: B<Any>, B<ArrayRef>, B<Bool>,
B<ClassName>, B<CodeRef>, B<Defined>, B<FileHandle>, B<GlobRef>,
B<HashRef>, B<Int>, B<Item>, B<Object>, B<Map>, B<Ref>, B<ScalarRef>,
B<Str>, B<Tuple>, B<Undef>, and B<Value>. (Note that B<Num> and
B<RegexpRef> are I<not> on that list.)
local/lib/perl5/Types/Standard.pm view on Meta::CPAN
}
return !!0;
}};
*_is_class_loaded =
Type::Tiny::_USE_XS
? \&Type::Tiny::XS::Util::is_class_loaded
: eval $is_class_loaded;
*_HAS_REFUTILXS = eval {
require Ref::Util::XS;
Ref::Util::XS::->VERSION( 0.100 );
1;
}
? sub () { !!1 }
: sub () { !!0 };
} #/ BEGIN
my $add_core_type = sub {
my $meta = shift;
my ( $typedef ) = @_;
local/lib/perl5/Types/Standard.pm view on Meta::CPAN
}
);
$meta->$add_core_type(
{
name => "CodeRef",
parent => $_ref,
constraint => sub { ref $_ eq "CODE" },
inlined => sub {
_HAS_REFUTILXS && !$Type::Tiny::AvoidCallbacks
? "Ref::Util::XS::is_plain_coderef($_[1])"
: "ref($_[1]) eq 'CODE'";
},
type_default => sub { return sub {}; },
}
);
my $_regexp = $meta->$add_core_type(
{
name => "RegexpRef",
parent => $_ref,
local/lib/perl5/Types/Standard.pm view on Meta::CPAN
}
);
$meta->$add_core_type(
{
name => "GlobRef",
parent => $_ref,
constraint => sub { ref $_ eq "GLOB" },
inlined => sub {
_HAS_REFUTILXS && !$Type::Tiny::AvoidCallbacks
? "Ref::Util::XS::is_plain_globref($_[1])"
: "ref($_[1]) eq 'GLOB'";
},
}
);
$meta->$add_core_type(
{
name => "FileHandle",
parent => $_ref,
constraint => sub {
local/lib/perl5/Types/Standard.pm view on Meta::CPAN
}
);
my $_arr = $meta->$add_core_type(
{
name => "ArrayRef",
parent => $_ref,
constraint => sub { ref $_ eq "ARRAY" },
inlined => sub {
_HAS_REFUTILXS && !$Type::Tiny::AvoidCallbacks
? "Ref::Util::XS::is_plain_arrayref($_[1])"
: "ref($_[1]) eq 'ARRAY'";
},
constraint_generator => LazyLoad( ArrayRef => 'constraint_generator' ),
inline_generator => LazyLoad( ArrayRef => 'inline_generator' ),
deep_explanation => LazyLoad( ArrayRef => 'deep_explanation' ),
coercion_generator => LazyLoad( ArrayRef => 'coercion_generator' ),
type_default => sub { return []; },
type_default_generator => sub {
return $Type::Tiny::parameterize_type->type_default if @_ < 2;
return undef;
local/lib/perl5/Types/Standard.pm view on Meta::CPAN
}
);
my $_hash = $meta->$add_core_type(
{
name => "HashRef",
parent => $_ref,
constraint => sub { ref $_ eq "HASH" },
inlined => sub {
_HAS_REFUTILXS && !$Type::Tiny::AvoidCallbacks
? "Ref::Util::XS::is_plain_hashref($_[1])"
: "ref($_[1]) eq 'HASH'";
},
constraint_generator => LazyLoad( HashRef => 'constraint_generator' ),
inline_generator => LazyLoad( HashRef => 'inline_generator' ),
deep_explanation => LazyLoad( HashRef => 'deep_explanation' ),
coercion_generator => LazyLoad( HashRef => 'coercion_generator' ),
type_default => sub { return {}; },
type_default_generator => sub {
return $Type::Tiny::parameterize_type->type_default if @_ < 2;
return undef;
local/lib/perl5/Types/Standard.pm view on Meta::CPAN
}
);
my $_obj = $meta->$add_core_type(
{
name => "Object",
parent => $_ref,
constraint => sub { blessed $_ },
inlined => sub {
_HAS_REFUTILXS && !$Type::Tiny::AvoidCallbacks
? "Ref::Util::XS::is_blessed_ref($_[1])"
: $maybe_load_modules->(
'Scalar::Util',
"Scalar::Util::blessed($_[1])"
);
},
is_object => 1,
}
);
$meta->$add_core_type(