May 2014 Archives

Entering MooseX, Cheaper by the Dozen

A Dozen is one of those great numbers that goes way back to the Assyrian empire so today was just a little writing up what I though would be my last .t for my new MooseX and then put this project to bed by throwing it up on CPAN. I was wrong.

Well it seems I have a little bug in my .t files. I was happily doing today's .t and about half way though I ran into this

 

D:\Blogs\Moosex-AuthorizedMethodRoles\t\30-Instance.t ..
1..3
ok 1 - use MooseX::AuthorizedMethodRoles;
o…

Entering MooseX, Part the Eleventh

Well still milking this one for all its worth and today I will do another .t file.

This time round I am going to test the API validation. You might remember that I did add a little validation code and this is one that really should be tested. Many is the time where a lovely API has been created but no validation so one was able to enter all sorts of nu-sanitized data and commands against the API.

So in my little API I want to check for at least one of my API keys and that if a key is present it points to an Array-Ref.

So here is what I came up with again very simpl…

Entering MooseX, Part the Tenth

Well back on the Moose path again and today a little post on my next test for my first little Moosex. Like I said in my last post I like my tests to be simple and functional.

I did have look at the test suite for MooseX-AuthorizedMethods and for me it was a little too Mooseish fro my tastes, I guess he was very keen on testing to see if bits of Moose worked rather than focusing on the functionality of the mod…

Well Live an Learn

Well one of those days again,

43536.jpg

wel…

Entering MooseX, Part the Ninth

Well reaching the end of the road here now that I did my code review I think it is now about time I sit down and write up my first .t files for my Moosex.

I always think it is best to keep your tests simple and small, but not too small so I usually use Test::More as that give me just a few dependencies but a good load of extras. I am also little old school with my testing style as I like the good old numbered and named test that cover only one part of functionality.

So to start o…

Entering MooseX, Part the Eight

Well getting close to the end of this little series and today I though it would be good to do a little code review to see if I could fined any holes.

So there was some suggestion about a new namespace 'CheckCallerRoles' and another 'AllowedMethodRoles' but I think as I cut down on the number of files I need I will just keep the present setup besides it is easy to understand.

Now there is the question of the actually API names themselves

  1. requires and
  2. one_of

Now looking at the semantics of these two I think a change may be in order. Now…

Entering MooseX, Part the Seventh

Well in my last post I created a very small API of a two keys

  1. requires and
  2. one_of

Now I have to get down and dirty and write up some code to handle this API. Now the logic will be in the same place namely 'MooseX::Meta::Method::Role::Authorized' and in a rewritten 'authorized_do' sub.

Well I start out the same with

 
sub authorized_do {
my $self = shift;
my $method = shift;
my…

Entering MooseX, Part the Sixth

Well in my last post I decided to use a hash-ref rather than an array-ref as a way to expand my little MooseX and let the user set have a set of required roles and or a set where only one role is required from a set.

I figured this made the API a little eirer to understand and even read inline.

Now how to implement this?

Well I start first with 'MooseX::Meta::Method::Role::Authorized' do this

Entering MooseX, Part the Fith

Well just a sort one tonight as other moose-poop-21534987.jpg="text-align: center;…

Entering MooseX, Part the Fourth

Well in my last post I manged to get rid of numerous bits of the original MooseX::Authorized Methods and get it down to what I find is just what I need the bare-basic check if a class has a role.

Now digging ever deeper into the 'clone' of Authorized Methods I have the 'MooseX::Meta::Method::Role::Authorized::HasRoles' class and I can just delete that one as I moved its functionality into the 'MooseX::Meta::Method::Role::Au…

Entering MooseX, Part the Third

Now for my next installment I think I will carry on the same pattern as in my last post namely just taking the next file in line and bending it to my will. So lets see what is next.

Now my code base I have nothing in this name-space because I wanted to avoid a name-space collision as we all know you cannot have two files with the same name (well except in windows if the case is different). So under 'Method' I added another namespace called 'Role' and add my version of 'Authorized.pm'. there,

Entering MooseX, Part the Second

Well in my last post I managed to de-break my Perl by creating that was for all intensive purposes justa rename and a little rejigged clone of MooseX::Authorized Methods

So onto making this into something that I want.

Well might as well start at the beginning 'MooseX::AuthorizedMethodRoles'

So It starts with

 
package MooseX::AuthorizedMethodRoles;
use Moose…

Leaving Moose Entering MooseX

Well things are progressing for me. You might remember a resent post of mine where I badly injured my Perl and another post where I started down the road of healing. Well today I finally wrote my first MooseX a variation on MooseX::Authorized Methods which rather that using some sort of 'User' who has some sort of 'role' method I just set it up so the class…

Acme Comes Through Again

Well was programming away today (after doing 8 hours of unpaid household chores) and I had to do the old place a file in a dir but make sure you do not overwrite the last one trick.

There are of course all sorts of ways to do this but the most common is to use the current time in some way and add it into the file name. The good old Perl 'time' function is the quick and dirty way as it gets a slew of numbers any you can just tack it on the end like this

 
my $time = time;
my $file ="somefile.".$time;

Of course that will work but d…

On the Correct Path Again

Well back to Perl posting today. You might remember a very bad thing I did in my last post namely altering an installed module and thus breaking any chance of portability or at least maintainability of my current project.

Well the old story of short term expedience for long term failure is fine for the next few days but I really do need a better solution so in the end I will have to write some of my own code.

Well I was thinking of just writing a different version of '="https://metacpan.org/r…

Some days Don't Pay

Well No perl stuff today as I have spend the last 24 hours almost fully diconeccted for the real word.

My phone line died 100% just a buzz coming down the line. I checked my DSL which is supposed to separate and it was down as well so a call out to Ma-Bell and the standard

A technicia will call sometime today between 08:00 and 17:00. So up early off to my local coffee shop to work for the day till they guy calls to come and fix whatever.

Well after 1 hour and 3 coffees I was asked to leave and off to the local McDs where after 30min and two coffees I was kicked …

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…

Well Back on The Moose Track

So after my little crash yesterday I had to revisit my decision to use 'MooseX::AuthorizedMethods' as I was using it totally wrong. It seems to have been defaulted to use a 'User' class of some sort that has a roles method on it which is checked against a passed in array-ref of roles.

Here I was thinking it was checking for 'Moose::Role' classes applied to the calling class and doing all sorts of neat Mossey stuff when in fact this is m…

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 w…

You Can't Get there From Here

My last few posts you may of noticed I have been using Moose with a more professional end in mind rather than my usual playing about with AD&D so I figured I might as well keep going on with it a bit as these are real world (well at least my world) situations rather than contrived gaming stuff. As well my latest round of work is a great source of posts.

Well on the platter today is 'MooseX::AuthorizedMethods' char broiled au jus wit…

A Little Moose Help

Well I was busily writing some tests for a large processor interface where you would pass an object too it and it will merrily process away on it. Well all of the object I was passing into it are written in Moose and I did not need to test the 'State' or 'values' of these object, what I needed to tests where some of the lower-level admin functions in the interface, that really had nothing to do with the objects themselves more about reading config files connecting and alike.

The problem I was having was to test the 'Interface' I had to give it a valid 'object' as that was a 'required…

Over Stuffed Moose

Sometimes being both newbie and a keener can be a dangerous combination. Well today I sort of fell into that trap.

Well I started doing the first refactoring of my Moose classes (not for AD&D this time this is some real world code) I was working with. So I wanted to move all the common bits into a single role then create a few 'base' classes that comsume that base roles and add some other sutff. Finally I was going to 'extend' these classes with some default values and then polish them by adding a few roles to customize the end product.

So like this

="…

Omnia illa, Quae Exspectant

Or to put in other words if you hang around long enough things will change. Well I actually did not have to wait very long at all about a month only. You may remember this post where I was recursively digging in to a directory of code to pre-load a number of Moose classes.

Well I had a solution to fix this problem


Can't locate object method "new_object" via package "Moose::Meta::Role" at /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/Moose/Object.pm line 2…

Are They taking over?

Well after I intercepted this recording secret meeting of the order of Cats (sorry for the commercials but it is a public broadcaster) and as part of their evil plan they

Seem they have some sort of strange influence over PACKMAN and he has recently released 'Acme::CatFS'. Now anyone can do this Cat…

Still Cold eh!

Well you might of read my recent post on 'Temperature-Windchill' and as I have a few mins I think I will use this post to create and send in a patch to this mod so us Canuck's can us it to on near calm days.

Well I should first provide a little background to justify my patch so here is a link NOAA Wind chill calculatior

and the formula as stolen from the Canadian website

wind = 5 ) ) {
chill=(temp +((-1.59+0.1345*temp)/5)*win…

Finally a Perl Mod for Canadians

Well I finally found a Perl mod that was just made for us Canadians (and maybe the Fennoscandias as well). Well when you live where you have snow on the ground at sea level for 6 months of the year and you can get snow 9 months out of a possible 12 this mod is a good one to have around.

I am talking about 'Temperature::Windchill' or how cold does exposed skin feel when there is a wind out-side.

Well if you are like me and spend any time outdoors in a Canadian winter you pay attention to such things as it really …

A Perl Classic

Well if you have been working with Perl long enough you are more than likely to have run into the situation where you are playing with a code base that is shall we say a little dated.

Of course being a good modern Perl programmer you will want to take advantage object-oriented programing or newer version of modules that do more but need a more modern Perl.

Sometime you are stuck in one version of Perl and are forced to write some of you own modules like my Orignal which gave me rather simple attributes when faced with Perl 5…

Is that Meta Moose or Moose Meta?

I had an interesting discussion to day with a programming friend of mine and we got onto to topic of metadata and as the last few posts I have made have been using metadata (or at least I hope I was)

My friend comes from a DB background so to him metadata was is and ever shall be just data that describes data, You know what I mean the indexes, fields, types tables ect all the annoying minutia of programming. I of course come at it in a different manner I see it as more of a guide to understanding the data.

Well we both agreed it is at some wishy washy mid point that these two…

Do Even more with Meta (Yet Another Moose Meta Trick IV)

Well in my last post I left of with my serializer working for boolean and json and recursing down into itself to work for objects, well one object anyway, and I left it at that with the gaping hole in my code if I need to look at any deeper objects.

Well I am in luck again as 'MooseX::MetaDescription' not only works for 'Attributes' It can also be applied at the 'Class' level.

It is a little mo…

Do More With Recusion (Yet Another Moose Meta Trick)

So I am happily programming along with my nice shiny new 'Serializer' sub that I have cobbled together over the last few post and it is now looking something like this



sub as_hash {
use Data::Dumper;
my $self = shift;
my ($serialize_on) = @_;
my $return_hash;
my @attributes = $self->meta->get_attribute_list();
foreach my $attr (@attributes){
my $field = $self->meta->get_attribute($attr);
next
unl…

About byterock

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