Ref-Util
view release on metacpan or search on metacpan
lib/Ref/Util/PP.pm view on Meta::CPAN
package Ref::Util::PP;
$Ref::Util::PP::VERSION = '0.204';
# ABSTRACT: pure-Perl version of Ref::Util
use strict;
use warnings;
use Carp ();
use Scalar::Util ();
use Exporter 5.57 'import';
use constant _FORMAT_REFS_WORK => ("$]" >= 5.007);
use constant _RX_NEEDS_MAGIC => (Scalar::Util::reftype(qr/^/) ne 'REGEXP');
our %EXPORT_TAGS = ( 'all' => [qw<
is_ref
is_scalarref
is_arrayref
is_hashref
is_coderef
is_regexpref
is_globref
is_formatref
is_ioref
is_refref
is_plain_ref
is_plain_scalarref
is_plain_arrayref
is_plain_hashref
is_plain_coderef
is_plain_globref
is_plain_formatref
is_plain_refref
is_blessed_ref
is_blessed_scalarref
is_blessed_arrayref
is_blessed_hashref
is_blessed_coderef
is_blessed_globref
is_blessed_formatref
is_blessed_refref
>] );
our @EXPORT = ();
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
sub _using_custom_ops () { 0 }
if (_RX_NEEDS_MAGIC) {
require B;
*_is_regexp = sub {
no warnings 'uninitialized';
return 0 if ref($_[0]) eq '';
my $o = B::svref_2object($_[0]) or return 0;
return 0 if Scalar::Util::blessed($o) ne 'B::PVMG';
my $m = $o->MAGIC;
while ($m) {
return 1 if $m->TYPE eq 'r';
$m = $m->MOREMAGIC;
}
return 0;
lib/Ref/Util/PP.pm view on Meta::CPAN
}
sub is_blessed_scalarref($) {
Carp::croak("Too many arguments for is_blessed_scalarref") if @_ > 1;
my $reftype = Scalar::Util::reftype( $_[0] );
defined Scalar::Util::blessed( $_[0] )
&& ($reftype eq 'SCALAR' || $reftype eq 'VSTRING')
&& (!_RX_NEEDS_MAGIC || !_is_regexp( $_[0] ));
}
sub is_blessed_arrayref($) {
Carp::croak("Too many arguments for is_blessed_arrayref") if @_ > 1;
defined Scalar::Util::blessed( $_[0] )
&& Scalar::Util::reftype( $_[0] ) eq 'ARRAY';
}
sub is_blessed_hashref($) {
Carp::croak("Too many arguments for is_blessed_hashref") if @_ > 1;
defined Scalar::Util::blessed( $_[0] )
&& Scalar::Util::reftype( $_[0] ) eq 'HASH';
}
sub is_blessed_coderef($) {
Carp::croak("Too many arguments for is_blessed_coderef") if @_ > 1;
defined Scalar::Util::blessed( $_[0] )
&& Scalar::Util::reftype( $_[0] ) eq 'CODE';
}
sub is_blessed_globref($) {
Carp::croak("Too many arguments for is_blessed_globref") if @_ > 1;
defined Scalar::Util::blessed( $_[0] )
&& Scalar::Util::reftype( $_[0] ) eq 'GLOB';
}
sub is_blessed_formatref($) {
_FORMAT_REFS_WORK
or
Carp::croak("is_blessed_formatref() isn't available on Perl 5.6.x and under");
Carp::croak("Too many arguments for is_blessed_formatref") if @_ > 1;
defined Scalar::Util::blessed( $_[0] )
&& Scalar::Util::reftype( $_[0] ) eq 'FORMAT';
}
sub is_blessed_refref($) {
Carp::croak("Too many arguments for is_blessed_refref") if @_ > 1;
defined Scalar::Util::blessed( $_[0] )
&& Scalar::Util::reftype( $_[0] ) eq 'REF';
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Ref::Util::PP - pure-Perl version of Ref::Util
=head1 VERSION
version 0.204
=head1 SYNOPSIS
use Ref::Util;
=head1 DESCRIPTION
This module provides a pure-Perl implementation of the functions in
L<Ref::Util>.
Ref::Util:PP will be used automatically if Ref::Util is installed on a
system with no C compiler, but you can force its usage by setting either
C<$Ref::Util::IMPLEMENTATION> or the C<PERL_REF_UTIL_IMPLEMENTATION>
environment variable to C<PP>.
=head1 AUTHORS
=over 4
=item *
Sawyer X <xsawyerx@cpan.org>
=item *
Aaron Crane <arc@cpan.org>
=item *
Vikenty Fesunov <vyf@cpan.org>
=item *
Gonzalo Diethelm <gonzus@cpan.org>
=item *
Karen Etheridge <ether@cpan.org>
=back
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2017 by Sawyer X.
This is free software, licensed under:
The MIT (X11) License
=cut
( run in 0.608 second using v1.01-cache-2.11-cpan-39bf76dae61 )