Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Reference assessment techniques and how they fail

by kyle (Abbot)
on Feb 16, 2008 at 21:06 UTC ( [id://668351]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use strict;
    use warnings;
    
    use Test::More 'tests' => 34;
    use Scalar::Util qw( reftype blessed );
    
  2. 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' );
    
  3. or download this
    ok( ref $package_0 ne '', 'ref $package_0 ne ""' );
    ok( defined blessed $package_0, 'defined blessed $package_0' );
    
  4. or download this
    package Super1;
    package Super2;
    ...
    foreach my $class ( qw( Sub Super1 Super2 HASH ) ) {
        ok( $sub_class->isa( $class ), "\$sub_class->isa( '$class' )" );
    }
    
  5. 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" )' )
    +;
    
  6. 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' );
    
  7. or download this
    my @nothing_isa;
    {
    ...
        ok( grep( $_ eq $class, @nothing_isa ),
            "\$nothing is a '$class' according to \@ISA" );
    }
    
  8. 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' );
    
  9. 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' );
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://668351]
Approved by planetscape
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-19 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found