Entering MooseX, The Check is in the Mail

Well if you believed the title of this post then you will believe this one as well. So I left off yesterday with a failing .t

 
my $test2 = test_one_of_fail->new();
eval {
   $test2
->ping();
};

ok(scalar($@),"test_one_of_fail");

In the case I was able to run the 'ping' sub so it fail because I got nothing in the '$@'

Well after some time playing about which I will not bore you with too much I will just give you the nickel tour. I simple saved my test as a pl and then I gave it a go with the Padre debugger attempting to step though the code. Well after getting kicked out Padre I had enough and just added in a liberal amount warn statements in the various packages to see what was going on.

Eventually I stumbled into it and it seem I as a little quick off the mark in this post to change the code for 'MooseX::Meta::Method::Role::Authorized::Application::ToInstance;'

to just


 

package MooseX::Meta::Method::Role::Authorized::Application::ToInstance;

use Moose::Role;



after apply => sub {

   
my ($self, $role, $instance, $args) = @_;

   $instance
->meta->add_role($role);

};

I did some other testing and found that it was only my final test that hit this code. So lets see what was there before


 

after apply
=> sub {

   
my ($self, $role, $instance, $args) = @_;

   
my $original_body = $instance->body;

   
my $new_body = sub {

        $instance
->verifier->authorized_do($instance, $original_body, @_)

   
};



    # HACK! XXX!

   
# 1 - body is ro in Method, need to force the change,,,

    $instance
->{body} = $new_body;



    # 2 - need to reinstall the CODE ref in the glob

   
no warnings 'redefine';

   
no strict 'refs';

   
*{$instance->package_name.'::'.$instance->name} = $new_body;

};


so looking at this again I still think I will have to change it a little as I no longer have a 'verifier' on my instance so I will take that out and give my test a go (after I remove all my warns as they tend to bugger up test results)


 

D
:\Blogs\Moosex-AuthorizedMethodRoles\t\40-Composed.t ..

1..2

ok
1 - one_of pass

ok
2 - test_one_of_fail

ok

All tests successful.

Files=1, Tests=2,  1 wallclock secs ( 0.02 usr +  0.02 sys =  0.03 CPU)

Result: PASS

and it works, Back in the game again. Though I wonder if I really need all of that code??
Playing around a bit I think I will have to keep it but to me it is not a hack more just a very Perlish way to do polymorphism (overloading) though it is the entire object with another version of itself

Now I think there is really really just one test left for me to do and that is using this as a 'trait' anyway time to make dinner

250px-SCchocolatemoose.JPG

Leave a comment

Sign in to comment.

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations