The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


MooseX::Role::Nameable - automatic class short names


Version 1.01


This role provides a method to automatically generate a short name for a Moose class from the package name. This is especially useful for classes that are used in conjunction with the factory pattern. When this role is included, the name for the access function is required. In addition, a regex may be defined to modify how the value is extracted. By default, the last namespace in the package is used. The short name assumes the package is in camel-case and normalizes it following some simple rules:

        - convert to lower case
        - words are separated by underscores
        - acronyms are treated as a single word

Example usage:

        package Foo::Base;
        use Moose;
                'MooseX::Role::Nameable' => {name => 'type'},
                'MooseX::Role::Nameable' => {name => 'nationality', regex => qr{::([^:]+)Child$}};

        package Foo::AmericanChild;
        use Moose;
        extends 'Foo::Base';

        package Foo::BritishChild;
        use Moose;
        extends 'Foo::Base';

        package main;

        my $child1 = Foo::AmericanChild->new;
        my $child2 = Foo::BritishChild->new;

        local $\="\n";
        print $_->type . ':' . $_->nationality for ($child1, $child2);
        # =>
        # american_child:american
        # british_child:british


Aaron Cohen, <aarondcohen at>


This module was made possible by Shutterstock (@ShutterTech). Additional open source projects from Shutterstock can be found at


Please report any bugs or feature requests to bug-MooseX-Role-Nameable at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc MooseX::Role::Nameable

You can also look for information at:


Copyright 2013 Aaron Cohen.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.