Just Call Me Lucky

It seems I lucked out big time with my last post it turns out I was a little mistaken on how 'MooseX::AuthorizedMethods' works.

As you see I ran into this problem today


Can't locate object method "user" via package 'Product::Move at C:/Dwimperl/perl/site/lib/MooseX/Meta/Method/Authorized/CheckRoles.pm line 13.

That is very odd I thought as it was the same sort of code I used the other day

package Product::Moves;
use MooseX::AuthorizedMethods;

authorized bin_swap => [qw(Product::BRULE::Bin ], sub {

Well after a little bit of looking at the offending line and then going back and re-reading the POD it dawned on me.

"makes a verification if the user has the required permissions"

and then in the code example

has user => (is => 'ro');

What gives? If the above is failing why do my tests and modules from before work?? So I had a quick look and it seemes in my 'Product::Order' class I had this
has current_user  (
    alias => [ qw(user) ],

which would get the current application user and then when this line of code ran
   my ($instance) = @_;
   my $user = $instance->user;

in 'CheckRoles.pm' it was happy because I was running my test with my super user who had all the roles.

Now in the 'Product::Moves' package doesn't have a user as it is used in a back-end inventory script, hence my code died.

So I guess I going to half to revisit some code in the next day or two and see if I can have my own custom validator.

Oh well I should really read the fine print, but it is rather funny how far I got along before it came to a crashing halt!


use of

Leave a comment

About byterock

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