Re: MooX::HandlesVia problem

[email protected] (Stephen Quinney) Wed, 19 Aug 2015 17:57:34 +0100
Newsgroups perl.moose
Message-ID <CAJ+y7SxGCdzkA_EoS7mD0BG=6sV=2CzxNiBOqHexpi4Xs6Xn6g@mail.gmail.com>
--94eb2c0338d463250d051dacee47
Content-Type: text/plain; charset=UTF-8

To partially answer my own question, it appears that if I use "with" once
for each role it works fine, for example:

{
    package SJQ::Baz;
    use Moo;

    with 'SJQ::Role::Foo';
    with 'SJQ::Role::Bar';

    use namespace::clean;
}

I'm still not clear on why that is necessary though.




On 19 August 2015 at 16:03, Stephen Quinney <[email protected]> wrote:

> I have a problem with using MooX::HandlesVia for attributes in roles when
> I consume more than one role in a class. I get:
>
> "Due to a method name conflict between roles 'SJQ::Role::Bar and
> SJQ::Role::Foo', the method 'has' must be implemented by 'SJQ::Baz' at
> /usr/share/perl5/vendor_perl/Role/Tiny.pm line 215."
>
> I can't see what I'm doing wrong here, any suggestions?
>
> Here's an example:
>
> {
>     package SJQ::Role::Foo;
>     use Moo::Role;
>     use MooX::HandlesVia;
> }
>
> {
>     package SJQ::Role::Bar;
>     use Moo::Role;
>     use MooX::HandlesVia;
> }
>
> {
>     package SJQ::Baz;
>     use Moo;
>
>     with 'SJQ::Role::Foo','SJQ::Role::Bar';
>
>     use namespace::clean;
> }
>
> my $test = SJQ::Baz->new();
>
>
>
>

--94eb2c0338d463250d051dacee47
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>To partially answer my own question, it appears that =
if I use &quot;with&quot; once for each role it works fine, for example:<br=
><br>{<br>=C2=A0=C2=A0=C2=A0 package SJQ::Baz;<br>=C2=A0=C2=A0=C2=A0 use Mo=
o;<br><br>=C2=A0=C2=A0=C2=A0 with &#39;SJQ::Role::Foo&#39;;<br>=C2=A0=C2=A0=
=C2=A0 with &#39;SJQ::Role::Bar&#39;;<br><br>=C2=A0=C2=A0=C2=A0 use namespa=
ce::clean;<br>}<br><br></div>I&#39;m still not clear on why that is necessa=
ry though.<br><br><br><div><br></div></div><div class=3D"gmail_extra"><br><=
div class=3D"gmail_quote">On 19 August 2015 at 16:03, Stephen Quinney <span=
 dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_blan=
k">[email protected]</a>&gt;</span> wrote:<br><blockquote class=3D"gm=
ail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-le=
ft:1ex"><div dir=3D"ltr"><div>I have a problem with using MooX::HandlesVia =
for attributes in roles when I consume more than one role in a class. I get=
:<br><br>&quot;Due to a method name conflict between roles &#39;SJQ::Role::=
Bar and SJQ::Role::Foo&#39;, the method &#39;has&#39; must be implemented b=
y &#39;SJQ::Baz&#39; at /usr/share/perl5/vendor_perl/Role/Tiny.pm line 215.=
&quot;<br><br></div><div>I can&#39;t see what I&#39;m doing wrong here, any=
 suggestions?<br><br></div>Here&#39;s an example:<br><div><div><br>{<br>=C2=
=A0=C2=A0=C2=A0 package SJQ::Role::Foo;<br>=C2=A0=C2=A0=C2=A0 use Moo::Role=
;<br>=C2=A0=C2=A0=C2=A0 use MooX::HandlesVia;<br>}<br><br>{<br>=C2=A0=C2=A0=
=C2=A0 package SJQ::Role::Bar;<br>=C2=A0=C2=A0=C2=A0 use Moo::Role;<br>=C2=
=A0=C2=A0=C2=A0 use MooX::HandlesVia;<br>}<br><br>{<br>=C2=A0=C2=A0=C2=A0 p=
ackage SJQ::Baz;<br>=C2=A0=C2=A0=C2=A0 use Moo;<br><br>=C2=A0=C2=A0=C2=A0 w=
ith &#39;SJQ::Role::Foo&#39;,&#39;SJQ::Role::Bar&#39;;<br><br>=C2=A0=C2=A0=
=C2=A0 use namespace::clean;<br>}<br><br>my $test =3D SJQ::Baz-&gt;new();<b=
r><br><br><br></div></div></div>
</blockquote></div><br></div>

--94eb2c0338d463250d051dacee47--