Well Why Not!

A question I relly have to ask myself more often. Well today I really got tired of my little solution to yesterdays Moose woes. I just couldn't take the sight of all of these

 
authorized bin_swap =>  [qw(Product::BRULE::Bin ], sub {
...
},(verifier=>Product::BRULE::Authorize->new())

instance calls in my nice clean code base. I did try a few little changes such as a global variable uck, and a singleton not bad but in the end I bit the bullet and decided that I need to add in some code of my own under MooseX.

The main reason is I liked how this worked and in a very elegant solution to to my code-base that can essilly extended with only a minor code change to a few roles if need be.

So into the Heart of Darkness go I.

Well first I started from the bottom up and copied my 'Product::BRULE::Authorize' class into the same directory where 'MooseX::Meta::Method::Authorized::CheckRoles' is. I then renamed it to 'HasRoles' and renamed the package as 'MooseX::Meta::Method::Authorized::HasRoles'

Well that was easy next I just went into 'MooseX::Meta::Method::Authorized'
and made this patch

 
--  use aliased 'MooseX::Meta::Method::Authorized::CheckRoles';
++  use aliased 'MooseX::Meta::Method::Authorized::HasRoles';


--  my $default_verifier = CheckRoles->new();
++  my $default_verifier = HasRoles->new();

Then went back into my code base and removed all those offensive 'Product::BRULE::Authorize->new()' back to what I had originally

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

Reran my tests and all was good.

Now this is not the recommend thing to do as anyone who comes along after me and re-installs or updates MooseX-AuthorizedMethods will break all of my code, as well I have just broken my Perl as it is no longer standard and if I was to try and install my code on a 'Debian' box it would break for sure.

So what to do. Well maybe a better solution tomorrow??

Xmas Moose.jpg

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