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

NAME

MooseX::APIRole - automatically create API roles for your classes and roles

VERSION

version 0.01

SYNOPSIS

If you write a Moose class like this:

    package Class;
    use Moose;
    use MooseX::APIRole;
    use true;
    use namespace::autoclean;

    sub foo {}

    make_api_role 'Class::API';

    __PACKAGE__->meta->make_immutable;

MooseX::APIRole will automatically create an API role like this:

    package Class::API;
    use Moose::Role;

    requires 'foo';

And apply it to your class.

If you forget what you called the API role, or don't want the API role to have a name, you can get at it via the metaclass:

    my $role = Class->meta->get_api_role;

You can then treat $role like you would any other role.

You can also create API roles for roles:

    package Role;
    use Moose::Role;
    use MooseX::APIRole;
    use true;
    use namespace::autoclean;

    sub foo {}
    requires 'bar';

    make_api_role 'Role::API';

This results in the following role:

    package Role::API;
    use Moose::Role;

    requires 'foo';
    requires 'bar';

If you do not call make_api_role or apply_api_role, you can still get the lazily-built anonymous API role via the metaclass. But the class won't does_role the role, which could be confusing.

DESCRIPTION

Inheritance is handled such that if Subclass extends Class with API role APIRole, Subclass will also do the APIRole. The same applies to roles; if Role does RoleAPI and AnotherRole consumes Role, then AnotherRole will also do RoleAPI.

Wunderbar.

FUNCTIONS

You can control the behavior of this module by calling these imported functions:

set_api_role_name(ClassName)

This is the namespace that you want the API role to be in. The results of using an existing class name are undefined. It's likely that demons will come out of your nose and all your plants will die. So come up with a unique name.

apply_api_role

If you want the API role to be applied to your class or role, call this function.

You almost always want to do this, but it can't be done automatically for the same reason that Class->meta->make_immutable can't be done automatically.

make_api_role(ClassName)

Works like set_api_role_name followed by apply_api_role.

SEE ALSO

See MooseX::APIRole::Meta for the metaclass attributes you get.

AUTHOR

Jonathan Rockway <jrockway@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Jonathan Rockway.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.