- or download this
use strict;
use warnings;
use Test::More 'tests' => 34;
use Scalar::Util qw( reftype blessed );
- or download this
my $package_0 = bless {}, '0';
ok( ! ref $package_0, '! ref $package_0' );
ok( ! blessed $package_0, '! blessed $package_0' );
is( reftype $package_0, ref {}, 'reftype $package_0' );
- or download this
ok( ref $package_0 ne '', 'ref $package_0 ne ""' );
ok( defined blessed $package_0, 'defined blessed $package_0' );
- or download this
package Super1;
package Super2;
...
foreach my $class ( qw( Sub Super1 Super2 HASH ) ) {
ok( $sub_class->isa( $class ), "\$sub_class->isa( '$class' )" );
}
- or download this
my $pretend_array = bless {}, 'ARRAY';
is( ref $pretend_array, ref [], 'ref of fake array looks real' );
ok( UNIVERSAL::isa( $pretend_array, 'ARRAY' ),
'UNIVERSAL::isa thinks it is an array' );
ok( $pretend_array->isa( 'ARRAY' ), '$pretend_array->isa( "ARRAY" )' )
+;
- or download this
package Void;
sub void_sub { 'void sub' }
...
ok( UNIVERSAL::isa( [], 'ARRAY' ), 'isa still works' );
ok( ! UNIVERSAL::isa( {}, 'ARRAY' ), 'isa still works (negation)' );
is( $nothing->void_sub(), 'void sub', 'method dispatch still works' );
- or download this
my @nothing_isa;
{
...
ok( grep( $_ eq $class, @nothing_isa ),
"\$nothing is a '$class' according to \@ISA" );
}
- or download this
package NotHash;
use overload '%{}' => sub { {} };
...
# Useless use of a variable in void context
ok( eval { %{$not_hash}; 1 },
'$not_hash can be dereferenced as a hash' );
- or download this
package EvilHash;
use overload '%{}' => \&conditional_reference;
...
'$evil_hash will not be dereferenced inside eval' );
ok( scalar %{$evil_hash},
'$evil_hash allows dereference ouside eval' );