NAME

Fennec::Assert::Core::Anonclass - Easily build a temporary class

DESCRIPTION

Sometimes you need a class that uses a module or implements some functionality in order to test another module. This provides a simple way to do that.

SYNOPSIS

use Fennec::Assert::Core::Anonclass;

my $anonclass = anonclass(
    use => $package || \@packages
    isa => $base || \@bases,
    accessors => \@accessor_names,
    subs => {
        name => sub { ... },
        ...
    },
);

# can() and isa() check against the anonymous class, not the
# Fennec::Assert::Core::Anonclass package.
ok( $anonclass->can( ... ));
ok( $anonclass->isa( ... ));

# You can instanciate your class
my $instance = $anonclass->new( ... );

# You can use all core testing functions as methods on your object
$instance->is_deeply( $want, $name );
$instance->can_ok( @list );
$instance->isa_ok( $base );

1;

SCOPE WARNING

The anonymous class will be destroyed when the $anonclass object and all instances fall out of scope. This will most likely never be a problem, but it is important to know.

CLASS METHODS

$instance = $anonclass->new( ... )

Create a new instance of the anonymous class. Will call any new() method provided during anonclass construction, otherwise will bless a hashref containing any params provided.

$subref = $anonclass->can( $name )

can() on an anonclass object will act against the blessed anonymous class, not against the anonclass package.

$bool = $anonclass->isa( $package )

isa() on an anonclass object will act against the blessed anonymous class, not against the anonclass package.

$package = $anonclass->class()

Return the full package name of the anonymous class. This will be a strange looking package name with seemingly random characters at the end, but it is valid until the anonclass object is destroyed.

AUTHORS

Chad Granum exodist7@gmail.com

COPYRIGHT

Copyright (C) 2010 Chad Granum

Fennec is free software; Standard perl licence.

Fennec is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.