Adding roles to a CPAN module

Tony Edwardson Tony.Edwardson at
Tue Dec 13 01:28:59 PST 2011

Thanks – that looks like just what I need

From: jan.henning at [mailto:jan.henning at] On Behalf Of Jan Henning Thorsen
Sent: 13 December 2011 09:23
To: Tony Edwardson
Cc: miltonkeynes-pm at
Subject: Re: Adding roles to a CPAN module

I suggest using Module::Find:

  use Module::Find 'usesub';
  with usesub "Whatever::Plugins";

That way you can see if the roles has conflicts. Adding one-and-one will not detect conflicts in the same way.
2011/12/13 Tony Edwardson <Tony.Edwardson at<mailto:Tony.Edwardson at>>
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<tel:%2B44%20%280%29%2020%207426%207569>
Mob.    +44 (0) 7712 100283<tel:%2B44%20%280%29%207712%20100283>
Email. Tony.Edwardson at<mailto:Tony.Edwardson at>

ForexClear Hotline +44 (0) 207 426 7917<tel:%2B44%20%280%29%20207%20426%207917>

Error! Filename not specified.


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<mailto:postmaster at>.

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<mailto:postmaster at>.

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<tel:%2B44%2020%207426%207000> Internet:

LCH.Clearnet SA, Siège Social, 18 rue du Quatre Septembre, 75002 Paris, Chambre de Compensation conformément au Code Monétaire et Financier.


MiltonKeynes-pm mailing list
MiltonKeynes-pm at<mailto:MiltonKeynes-pm at>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the MiltonKeynes-pm mailing list