Test::Able::Role - Test::Able::Role documentation


Test-Able documentation Contained in the Test-Able distribution.

Index


Code Index:

NAME

Top

Test::Able::Role -The Test::Able Role

SYNOPSIS

Top

 package MyTest::SomeRole;

 use Test::Able::Role;

 test some_test => sub {};

DESCRIPTION

Top

This is the Test::Able Role. It is an extension of Moose::Role in the same way as Test::Able is an extension of Moose for the purpose of handling test-related methods.

EXPORTED FUNCTIONS

Top

In addition to exporting for Moose::Role, Test::Able::Role will export a handful of functions that can be used to declare test-related methods. These functions are the same functions that Test::Able exports.

startup/setup/test/teardown/shutdown

A more Moose-like way to do method declaration. The syntax is similar to has in Moose except its for test-related methods.

These start with one of startup/setup/test/teardown/shutdown depending on what type of method you are defining. Then comes any attribute name/value pairs to set in the Test::Able::Role::Meta::Method-based mehod metaclass object. The last pair must always be the method name and the coderef. This is to disambiguate between the method name/code pair and any another attribute in the method metaclass that happens to take a coderef. See the synopsis or the tests for examples.

AUTHOR

Top

Justin DeVuyst, justin@devuyst.com

COPYRIGHT AND LICENSE

Top


Test-Able documentation Contained in the Test-Able distribution.
package Test::Able::Role;

use Moose::Role;
use Moose::Exporter;
use Moose::Util::MetaRole;
use strict;
use Test::Able::Role::Meta::Method;
use warnings;

Moose::Exporter->setup_import_methods(
    with_caller => [
        qw( startup setup test teardown shutdown ),
    ],
    also => 'Moose::Role',
);

sub init_meta {
    shift;
    my %options = @_;

    my $m = Moose::Role->init_meta( %options, );

    return Moose::Util::MetaRole::apply_metaroles(
        for            => $options{for_class},
        role_metaroles => {
            method     => [ 'Test::Able::Role::Meta::Method', ],
        },
    );
}

sub startup  { return __add_method( type => 'startup',  @_, ); }
sub setup    { return __add_method( type => 'setup',    @_, ); }
sub test     { return __add_method( type => 'test',     @_, ); }
sub teardown { return __add_method( type => 'teardown', @_, ); }
sub shutdown { return __add_method( type => 'shutdown', @_, ); }

sub __add_method {
    my $class = splice( @_, 2, 1, );
    my ( $code, $name, ) = ( pop, pop, );

    my $meta = Moose::Meta::Class->initialize( $class, );
    $meta->add_method( $name, $code, );

    if ( @_ ) {
        my $method = $meta->get_method( $name, );
        my %args = @_;
        while ( my ( $k, $v ) = each %args ) {
            $method->$k( $v );
        }
    }

    return;
}

1;