The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Acme::Teddy - Chewy target for your pitbull testing module

VERSION

This document describes Acme::Teddy version 1.002003

SYNOPSIS

    # teddytest.t
    {
        package Acme::Teddy;
        sub chewtoy{ 'Squeek!' };
        our $yogi   = 'bear';
    }
    package main;
    use Acme::Teddy qw( chewtoy $yogi );
    use Test::More tests => 2;
    is( chewtoy(),  'Squeek!',          'teddy-squeek'  );
    is( $yogi,      'bear',             'teddy-bear'    );

    # teddytest-oo.t
    {
        package Acme::Teddy;
        sub talk{ 'Yabba dabba do!' };
    }
    package main;
    use Acme::Teddy;
    use Test::More tests => 1;
    my $bear    = Acme::Teddy::new();
    my $talk    = $bear->talk();
    is( $talk,      'Yabba dabba do!',  'teddy-oo-talk'    );

DESCRIPTION

Do what you can, with what you have, where you are. --Teddy Roosevelt

Testing modules need something to test. Acme::Teddy is all things to all bears.

Switch into package Acme::Teddy in your test script, define whatever you like there. Then switch back to package main and test your testing module.

Note that it is often completely unnecessary to use this module! You can achieve similar results with:

    {
        package Frobnitz::Blowhard;
        sub foo{ return 'foo' . shift };
    }
    print Frobnitz::Blowhard::foo('bar');

Although you may find it slightly more convenient, the main purpose of Acme::Teddy is to give you the comfort of using a "real" module.

FUNCTIONS/METHODS

import()

This is a cut-down copy of Exporter::Heavy::heavy_export() (the same routine that Exporter uses normally to export stuff on request).

There are two reasons we don't say @ISA = qw(Exporter);. We don't want to introduce any dependencies whatsoever; and we offer caller the freedom to export anything at all. Almost no checking is done of arguments passed to import() (normally, on the use() line).

new()

    my $bear    = $class->new($ref, @args);

This is a flexible, robust, subclassable object constructor.

    my $bear    = Acme::Teddy->new();
    my $bear    = Acme::Teddy->new( [] );
    my $bear    = Acme::Teddy->new( \&my_sub );
    my $bear    = Acme::Teddy->new( { -a  => 'x' } );
    my $bear    = Acme::Teddy->new( [ 1, 2, 3, 4 ] );
    my $bear    = Acme::Teddy->new( {}, @some_data );

It will bless any reference. If invoked with $class only, blesses an empty hashref and calls "init()" with no arguments.

If invoked with $class and a reference, blesses the reference and calls "init()" with any remaining @args.

init()

This is a placeholder method. You might want to override it in a subclass. For common initializations, you can just invoke "new()" with initial data.

INTERFACE

    {
        package Acme::Teddy;
        # Your target code here.
    }
    package main;
    use Acme::Teddy;
    use Test::Your::Testing::Module;
    # Your test here. 

Start a test script with a bare block in AT (or subclass it). Then define whatever behavior you like. After you switch into "your own" package, test for that behavior. You should be able to verify by eye that your expectations are correct; therefore, you can concentrate on debugging your testing module.

Writing the bare block is just like writing a module, except that much of the dull work is done for you.

Lexical declarations will "leak" across package boundaries if you leave off the bare block; so don't do that. It does not seem to be necessary to make this a BEGIN block; if you find any counterexample, please contact author.

Import whatever you like when you use Acme::Teddy. Be sure to define it, whatever it is. AT will attempt to export to caller everything you request.

You don't have to import anything. You can invoke a function (that you defined) with:

    my $return  = Acme::Teddy::my_button_nose();

Or invoke a method:

    $bear->talk();

Don't forget to define that method!

DIAGNOSTICS

$pkg: Can't export symbol: $type$sym

You tried to import something bizarre. Check your use() line.

Rationally, you can only export symbols from one package to another. These can be barewords, which will be interpreted as subroutines; scalar, array, or hash variables; coderefs; or typeglobs.

CONFIGURATION AND ENVIRONMENT

Acme::Teddy requires no configuration files or environment variables.

DEPENDENCIES

No dependencies.

INCOMPATIBILITIES

None.

BUGS AND LIMITATIONS

You really do have to define stuff yourself or it does nothing.

Lexical variables aren't found in package symbol tables.

THANKS

  • james2vegas of PerlMonks for improvements in the test script.

AUTHOR

Xiong Changnian <xiong@cpan.org>

LICENSE

Copyright (C) 2010 Xiong Changnian <xiong@cpan.org>

This library and its contents are released under Artistic License 2.0:

http://www.opensource.org/licenses/artistic-license-2.0.php