I suggest using Module::Find:<div><br></div><div>{</div><div>  use Module::Find 'usesub';<br><div>  with usesub "Whatever::Plugins";</div><div>}<br><br>That way you can see if the roles has conflicts. Adding one-and-one will not detect conflicts in the same way.<br>
<br><div class="gmail_quote">2011/12/13 Tony Edwardson <span dir="ltr"><<a href="mailto:Tony.Edwardson@lchclearnet.com">Tony.Edwardson@lchclearnet.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">










<div lang="EN-GB" link="blue" vlink="purple">

<div>

<p class="MsoNormal"><span style="font-size:11.0pt">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.<u></u><u></u></span></p>

<p class="MsoNormal"><span style="font-size:11.0pt">I want these optional roles
made available to the base module if they are installed.<u></u><u></u></span></p>

<p class="MsoNormal"><span style="font-size:11.0pt">Anyone got any idea how I can
get my base module to include these optional roles once they are installed ?<u></u><u></u></span></p>

<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>

<p class="MsoNormal"><span style="font-size:11.0pt">I have toyed with the
following ideas but they all have issues :-<u></u><u></u></span></p>

<p><u></u><span style="font-size:11.0pt"><span>1)<span style="font:7.0pt "Times New Roman"">      </span></span></span><u></u><span style="font-size:11.0pt">package ‘Whatever’;<br>
use Try::Tiny;<br>
use Moose;<br>
my @optional_roles = qw/ Blah Blah2 /;<br>
foreach my $optional_role ( @optional_roles ) {<br>
try {<br>
    with “Whatever::$optional_role”;<u></u><u></u></span></p>

<p><span style="font-size:11.0pt">}; # Ignore errors if
with fails<u></u><u></u></span></p>

<p><u></u><span style="font-size:11.0pt"><span>2)<span style="font:7.0pt "Times New Roman"">      </span></span></span><u></u><span style="font-size:11.0pt">package ‘Whatever’;<br>
use ExtUtils::Installed;<br>
use Carp;<br>
my $inst = ExtUtils::Installed->new();<br>
my @optional_roles = grep { /Whatever::/ } @{ $inst->modules() };<br>
foreach my $optional_role ( @optional_roles ) {<br>
try {<br>
    with “Whatever::$optional_role”;<br>
} catch {<br>
   croak “Failed to add role $optional_role: $_”;<br>
};<u></u><u></u></span></p>

<p><u></u><span style="font-size:11.0pt"><span>3)<span style="font:7.0pt "Times New Roman"">      </span></span></span><u></u><span style="font-size:11.0pt">Get the installer for my optional roles to maintain a
file containing the roles installed and refer to that in my base module<u></u><u></u></span></p>

<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>

<p class="MsoNormal"><span style="font-size:11.0pt">Is there a better way to
handle this ?<u></u><u></u></span></p>

<p><span style="font-size:11.0pt"><u></u> <u></u></span></p>

<p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p>

<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#00539f">Tony Edwardson<u></u><u></u></span></b></p>

<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#00539f">ForexClear Application Support<u></u><u></u></span></p>

<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#6b6c6d">Tel.      <a href="tel:%2B44%20%280%29%2020%207426%207569" value="+442074267569" target="_blank">+44 (0) 20 7426 7569</a><u></u><u></u></span></p>


<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#6b6c6d">Mob.    <a href="tel:%2B44%20%280%29%207712%20100283" value="+447712100283" target="_blank">+44 (0) 7712 100283</a><u></u><u></u></span></p>


<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#6b6c6d">Email.</span><span style="font-size:10.0pt;font-family:"Arial","sans-serif""> <a href="mailto:Tony.Edwardson@lchclearnet.com" target="_blank"><span style="color:blue">Tony.Edwardson@lchclearnet.com</span></a><u></u><u></u></span></p>


<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif""><u></u> <u></u></span></p>

<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">ForexClear
Hotline <a href="tel:%2B44%20%280%29%20207%20426%207917" value="+442074267917" target="_blank">+44 (0) 207 426 7917</a><u></u><u></u></span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif""><u></u> <u></u></span></p>

<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif""><img border="0" width="152" height="26" alt="lchclearnet_logo"><u></u><u></u></span></p>

<p class="MsoNormal"><u></u> <u></u></p>

</div>


<p><span style="font-family:'Arial';font-size:8pt">*************************************************************************************************</span></p>
<p><span style="font-family:'Arial';font-size:8pt"></span></p>
<p><span style="font-family:'Arial';font-size:8pt"> </span></p>
<p><span style="font-family:'Arial';font-size:8pt">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 <a href="mailto:postmaster@lchclearnet.com" target="_blank">postmaster@lchclearnet.com</a>.</span></p>

<p><span style="font-family:'Arial';font-size:8pt">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.</span></p>

<p><span style="font-family:'Arial';font-size:8pt">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.  </span></p>

<p><span style="font-family:'Arial';font-size:8pt">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 <a href="mailto:postmaster@lchclearnet.com" target="_blank">postmaster@lchclearnet.com</a>.</span></p>

<p><span style="font-family:'Arial';font-size:8pt">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é.</span></p>

<p><span style="font-family:'Arial';font-size:8pt">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 </span></p>

<p><span style="font-family:'Arial';font-size:8pt">Telephone: <a href="tel:%2B44%2020%207426%207000" value="+442074267000" target="_blank">+44 20 7426 7000</a>              Internet: <a href="http://www.lchclearnet.com" target="_blank">http://www.lchclearnet.com</a></span></p>

<p><span style="font-family:'Arial';font-size:8pt">LCH.Clearnet SA, Siège Social, 18 rue du Quatre Septembre, 75002 Paris, Chambre de Compensation conformément au Code Monétaire et Financier.</span></p>
<p><span style="font-family:'Arial';font-size:8pt"></span></p>
<p><span style="font-family:'Arial';font-size:8pt"> </span></p>
<p><span style="font-family:'Arial';font-size:8pt">*************************************************************************************************</span></p>
<p><span style="font-family:'Arial';font-size:8pt"> </span></p></div>


<br>_______________________________________________<br>
MiltonKeynes-pm mailing list<br>
<a href="mailto:MiltonKeynes-pm@pm.org">MiltonKeynes-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/miltonkeynes-pm" target="_blank">http://mail.pm.org/mailman/listinfo/miltonkeynes-pm</a><br>
<br></blockquote></div><br></div></div>