develooper Front page | perl.moose | Postings from February 2015

incomplete role consumption?

Thread Next
From:
Daniel Hermann
Date:
February 25, 2015 21:25
Subject:
incomplete role consumption?
Message ID:
54EE30D5.8050907@1und1.de
Hi,

I have two classes Test1 and Test2, both consuming the role
TestRole which uses another class TestGlue, which in turn uses
Test1 and Test2 internally.

My main program uses Test1 and Test2 and runs into a Moose error
when it calls a method in Test2 provided by TestRole:

    Can't locate object method "load_role" via package "Test2" at 
Test2.pm line 5.

What is going wrong here?

This is the full code:

=== TestRole.pm ===
package TestRole;
use Moose::Role;
use TestGlue ();

sub load_role {}

1;
==============

=== Test1.pm =====
package Test1;
use Moose;
with "TestRole";

sub load{ shift->load_role }

1;
==============

=== Test2.pm =====
package Test2;
use Moose;
with "TestRole";

sub load{ shift->load_role }

1;
==============

=== TestGlue.pm ===
package TestGlue;
use Moose;
use Test1 ();
use Test2 ();

1;
==============

=== main.pl =====
#!/usr/bin/env perl
use Test1 ();
use Test2 ();

Test1->new->load;
Test2->new->load;

1;
==============


The above code works if

- I do not 'use Test2' in TestGlue.pm or
- I use an eval block in main.pl such as

     eval { use Test2; Test2->new->load; };

It seems to me that the import of the class Test2 in "role context"
via TestGlue.pm, triggered by 'use Test1' in main.pl, is incomplete
somehow, and the second import via 'use Test2' in main.pl does
not compensate this.

Thanks for any hints,
Daniel

--
Daniel Hermann

Operations Developer
1&1 Internet AG


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About