in reply to Re^3: Moose: Accessing subroutines in packages used by Moose class
in thread Moose: Accessing subroutines in packages used by Moose class

Sorry, I'm pretty new to Moose and I'm not clear as to whether this applies to my situation where my Moose class is using the subroutines pulled in from a non-Moose module.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

  • Comment on Re^4: Moose: Accessing subroutines in packages used by Moose class

Replies are listed 'Best First'.
Re^5: Moose: Accessing subroutines in packages used by Moose class
by Arunbear (Prior) on Apr 18, 2016 at 16:05 UTC
    Yes, it applies to your situation. I couldn't install X11::GUITest, so I created a dummy package to illustrate the technique.

    The package 'Bogus' in my example is analogous to X11::GUITest in your example i.e. it contains the subs that you want to wrap.

    So translating to your example it would look like:
    package X11_GUITest_Wrapper; use Moose; use MooseX::NonMoose; extends 'X11::GUITest'; around [qw( SendKeys FindWindowLike ClickWindow SetEventSendDelay )] = +> sub { my $orig = shift; my $self = shift; $orig->(@_); }; 1;
    Then to use it:
    package FFMech; $ENV{'DISPLAY'} = ':0.0'; use Moose; use Modern::Perl; use MooseX::NonMoose; extends 'WWW::Mechanize::Firefox'; has 'x11_guitest_wrapper' => ( is => 'bare', default => sub { X11_GUITest_Wrapper->new }, handles => [qw( SendKeys FindWindowLike ClickWindow SetEventSendDe +lay )], ); # ... 1;
Re^5: Moose: Accessing subroutines in packages used by Moose class
by Corion (Patriarch) on Apr 18, 2016 at 15:13 UTC

    I think you should be able to adapt this to your needs by rewriting the package Bogus as follows:

    package Bogus; use strict; use X11::GUITest qw(SendKeys); # and whatever other functions

    (and maybe also renaming it away from Bogus to, say, Class::X11::GUITest), and then using that from the package MyBogus:

    package MyBogus; use Moose; use MooseX::NonMoose; extends 'Bogus'; around ...;

    In theory, you should even be able to do away with the intermediate Class::X11::GUITest class by using the following:

    package X11::GUITest::Moosified; use Moose; use MooseX::NonMoose; extends 'X11::GUITest'; around ['SendKeys'] => sub { ... };