Adding roles to a CPAN module

Tony Edwardson Tony.Edwardson at lchclearnet.com
Tue Dec 13 01:09:55 PST 2011


I am writing a new CPAN module which uses Moose and I want it to comprise of a base module and a set of optional add-on sub modules which simply add new functionality via Roles.
I want these optional roles made available to the base module if they are installed.
Anyone got any idea how I can get my base module to include these optional roles once they are installed ?

I have toyed with the following ideas but they all have issues :-

1)      package 'Whatever';
use Try::Tiny;
use Moose;
my @optional_roles = qw/ Blah Blah2 /;
foreach my $optional_role ( @optional_roles ) {
try {
    with "Whatever::$optional_role";

}; # Ignore errors if with fails

2)      package 'Whatever';
use ExtUtils::Installed;
use Carp;
my $inst = ExtUtils::Installed->new();
my @optional_roles = grep { /Whatever::/ } @{ $inst->modules() };
foreach my $optional_role ( @optional_roles ) {
try {
    with "Whatever::$optional_role";
} catch {
   croak "Failed to add role $optional_role: $_";
};

3)      Get the installer for my optional roles to maintain a file containing the roles installed and refer to that in my base module

Is there a better way to handle this ?



Tony Edwardson
ForexClear Application Support
Tel.      +44 (0) 20 7426 7569
Mob.    +44 (0) 7712 100283
Email. Tony.Edwardson at lchclearnet.com<mailto:Tony.Edwardson at lchclearnet.com>

ForexClear Hotline +44 (0) 207 426 7917

[cid:image001.gif at 01CCB974.63D155B0]


*************************************************************************************************

This email is intended for the named recipient(s) only. Its contents are confidential and may only be retained by the named recipient(s) and may only be copied or disclosed with the consent of LCH.Clearnet Limited and/or LCH.Clearnet SA.   If you are not an intended recipient please delete this e-mail and notify postmaster at lchclearnet.com.
LCH.Clearnet Limited, LCH.Clearnet SA and each other member of the LCH.Clearnet Group accept no liability, including liability for negligence, in respect of any statement in this email.
The contents of this email are subject to contract in all cases, and LCH.Clearnet Limited and/or LCH.Clearnet SA makes no contractual commitment save where confirmed by hard copy.  
Cet e-mail et toutes les pièces jointes (ci-après le "message") sont confidentiels et établis à l'intention exclusive de ses destinataires. Toute utilisation de ce message non conforme à sa destination, toute diffusion ou toute publication, est interdite, sauf autorisation expresse de LCH.Clearnet Limited et/ou LCH.Clearnet SA. Si ce message vous a été adressé par erreur, merci de le détruire et d'en avertir immédiatement postmaster at lchclearnet.com.
LCH.Clearnet Limited, LCH.Clearnet SA et les autres entités du groupe LCH.Clearnet Group, ne peuvent en aucun cas être tenues responsables au titre de ce message à moins qu’il n’ait fait l’objet d’un contrat signé.
LCH.Clearnet Limited, Registered Office: Aldgate House, 33 Aldgate High Street, London EC3N 1EA.    Recognised as a Clearing House under the Financial Services & Markets Act 2000. Reg in England No.25932 
Telephone: +44 20 7426 7000              Internet: http://www.lchclearnet.com
LCH.Clearnet SA, Siège Social, 18 rue du Quatre Septembre, 75002 Paris, Chambre de Compensation conformément au Code Monétaire et Financier.

*************************************************************************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/miltonkeynes-pm/attachments/20111213/5d772aaa/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.gif
Type: image/gif
Size: 1915 bytes
Desc: image001.gif
URL: <http://mail.pm.org/pipermail/miltonkeynes-pm/attachments/20111213/5d772aaa/attachment.gif>


More information about the MiltonKeynes-pm mailing list