Skip to content

Commit

Permalink
import UNIVERSAL-isa 0.03 from CPAN
Browse files Browse the repository at this point in the history
git-cpan-module:   UNIVERSAL-isa
git-cpan-version:  0.03
git-cpan-authorid: NUFFIN
git-cpan-file:     authors/id/N/NU/NUFFIN/UNIVERSAL-isa-0.03.tar.gz
  • Loading branch information
nothingmuch authored and schwern committed Dec 13, 2009
1 parent b01b45e commit 57afc3e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 25 deletions.
4 changes: 2 additions & 2 deletions META.yml
@@ -1,6 +1,6 @@
---
name: UNIVERSAL-isa
version: 0.02
version: 0.03
author: ~
abstract: |-
Hack around stupid module authors using UNIVERSAL::isa as a
Expand All @@ -12,5 +12,5 @@ requires:
provides:
UNIVERSAL::isa:
file: lib/UNIVERSAL/isa.pm
version: 0.02
version: 0.03
generated_by: Module::Build version 0.2611
8 changes: 4 additions & 4 deletions Makefile.PL
Expand Up @@ -2,12 +2,12 @@
use ExtUtils::MakeMaker;
WriteMakefile
(
'PL_FILES' => {},
'INSTALLDIRS' => 'site',
'NAME' => 'UNIVERSAL::isa',
'VERSION_FROM' => 'lib/UNIVERSAL/isa.pm',
'PREREQ_PM' => {
'Scalar::Util' => 0
}
'Scalar::Util' => '0'
},
'INSTALLDIRS' => 'site',
'PL_FILES' => {}
)
;
18 changes: 9 additions & 9 deletions SIGNATURE
@@ -1,5 +1,5 @@
This file contains message digests of all files listed in MANIFEST,
signed via the Module::Signature module, version 0.44.
signed via the Module::Signature module, version 0.50.

To verify the content in this distribution, first make sure you have
Module::Signature installed, then type:
Expand All @@ -16,15 +16,15 @@ Hash: SHA1

SHA1 c90c2476bc82d060488d8ae50896dcda8ee4221f Build.PL
SHA1 cb3ff2dc987a0b6708a4760215065b3c08d4388e MANIFEST
SHA1 97221bde9191e7c4b54203aef1f5478cd2bea595 META.yml
SHA1 348c8145f3fdb3342ef6ab634db519745b781a51 Makefile.PL
SHA1 0c453919f49aec6fc5e5b689fd44d35de6351aa0 lib/UNIVERSAL/isa.pm
SHA1 6bba987abb95183f6373079eacc852ff060d8c39 t/basic.t
SHA1 c25e7e58bb5cb6c36f960be4fb4468ba2f16a1e8 t/bugs.t
SHA1 bf0b31daaabbf62e52c9b9f9d76253f2ae6e03e8 META.yml
SHA1 5cf0c1336517270a31f2b893775bb284130b672e Makefile.PL
SHA1 51acd043352dc970d0df6c9700cf7593c6d01ff2 lib/UNIVERSAL/isa.pm
SHA1 8497ba6abe4951ce5358a9bf4b57e908da7c37de t/basic.t
SHA1 49e60190b6d966c78a3a52b8fd55d0a312468c02 t/bugs.t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)

iD8DBQFCx+jQVCwRwOvSdBgRAsXVAJ9DQc0HHhWZM5BGLLSiljKKF/TYRwCgrUMd
GlpBh7KgLJoY5+gnt/rQBxE=
=/jQg
iD8DBQFDHEr1VCwRwOvSdBgRAqD1AJ0dIjNN73SpjeDJHGn7Z0b8Plq8nQCeMuoc
naUdFHFHIi325FKoEG1hjXk=
=rEL/
-----END PGP SIGNATURE-----
33 changes: 28 additions & 5 deletions lib/UNIVERSAL/isa.pm
@@ -1,14 +1,16 @@
#!/usr/bin/perl
#!/usr/bin/perl -w

package UNIVERSAL::isa;

use strict;
use warnings;
use vars qw/$VERSION $recursing/;

use UNIVERSAL ();

use Scalar::Util qw/blessed/;
use warnings::register;

our $VERSION = "0.02";
$VERSION = "0.03";

my $orig;
BEGIN { $orig = \&UNIVERSAL::isa };
Expand All @@ -21,6 +23,7 @@ sub import {
}

sub UNIVERSAL::isa {
goto &$orig unless defined $_[0];

# not an object or a class name, we can skip
unless ( blessed($_[0]) )
Expand All @@ -47,13 +50,19 @@ sub UNIVERSAL::isa {

# if we've been called from an overridden isa, we are either SUPER:: or explicitly called.
# in both cases the original ISA behavior is expected.
our $recursing;
goto &$orig if $recursing;

# the last possible case is that 'isa' is overridden
local $recursing = 1;
my $obj = shift;
return $obj->isa(@_);

if (warnings::enabled()) {
my $calling_sub = ( caller( 1 ) )[3] || '';
warnings::warn( "Called UNIVERSAL::isa() as a function, not a method" )
if $calling_sub !~ /::isa$/;
}

return $obj->isa(@_);
}

__PACKAGE__;
Expand Down Expand Up @@ -84,6 +93,20 @@ called on those objects as a method.
In all other cases the real C<UNIVERSAL::isa> is just called directly.
=head1 WARNINGS
If the lexical warnings pragma is available, a warning will be emitted for each
naughty invocation of C<UNIVERSAL::isa>. These warnings can be silenced by
saying:
no warnings 'UNIVERSAL::isa';
in the lexical scope of the naughty code.
=head1 SEE ALSO
L<UNIVERSAL::can> for a more mature discussion of the problem at hand.
=head1 AUTHORS
Autrijus Tang <autrijus@autrijus.org>
Expand Down
5 changes: 3 additions & 2 deletions t/basic.t
@@ -1,12 +1,13 @@
#!/usr/bin/perl
#!/usr/bin/perl -w

use strict;
use warnings;

use Test::More tests => 12;

BEGIN { use_ok("UNIVERSAL::isa", "isa") };

no warnings "UNIVERSAL::isa";

{
package Foo;

Expand Down
9 changes: 6 additions & 3 deletions t/bugs.t
@@ -1,12 +1,13 @@
#!/usr/bin/perl
#!/usr/bin/perl -w

use strict;
use warnings;

use Test::More tests => 4;
use Test::More tests => 5;

BEGIN { use_ok('UNIVERSAL::isa', 'isa') };

no warnings 'UNIVERSAL::isa';

# class method

{
Expand Down Expand Up @@ -67,3 +68,5 @@ my $quux = Quux->new();
ok( isa( 'Bar', 'Foo' ), 'isa() should work on class methods too' );
ok( ! isa( 'Baz', 'Foo' ), '... but not for non-existant classes' );
ok( isa( $quux, 'Foo' ), '... and should work on delegated wrappers' );

is( scalar(isa(undef, 'Foo')), undef, 'isa on undef returns undef');

0 comments on commit 57afc3e

Please sign in to comment.