Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Moose and static arrays

by hsmyers (Canon)
on Jan 21, 2011 at 05:05 UTC ( [id://883458]=perlquestion: print w/replies, xml ) Need Help??

hsmyers has asked for the wisdom of the Perl Monks concerning the following question:

Long ago in the pre Moose days I converted a great deal of data into a collection of hash tables with simple-minded code like (large hunks redacted/removed for brevity) the following:
package Chess::PGN::Moves; use 5.006; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( %King_Moves ); our $VERSION = '0.05'; use vars qw( %King_Moves ); %King_Moves = ( a1 => [qw(a2 b2 b1)], b1 => [qw(a2 b2 c2 a1 c1)], c1 => [qw(b2 c2 d2 b1 d1)], ); 1; __END__
My question now is what is the Moose equivalent of such a thing. That is how do I a take a collection of static information (all hash tables as it turns out) and bring them into the 21st century object-wise? It is clear that this is do-able in terms of a dynamic hash, but I don't understand the plumbing well enough to abstract from that to what I need for pre-declared material. I've seen references to http://search.cpan.org/~drolsky/Moose-1.21/lib/Moose/Meta/Attribute/Native.pm which I find relatively clear, but again, it doesn't seem to speak to the notion of pre-declared information.

--hsm

"Never try to teach a pig to sing...it wastes your time and it annoys the pig."

Replies are listed 'Best First'.
Re: Moose and static arrays
by ikegami (Patriarch) on Jan 21, 2011 at 10:05 UTC
    You might be thinking of something like MooseX::ClassAttribute, but it's serious overkill for constant data used internally.
Re: Moose and static arrays
by JavaFan (Canon) on Jan 21, 2011 at 13:42 UTC
    Where would you stop? What would you make an object? %King_Moves? Or should the list of possible moves also be objects? But even then, you can make the fields themselves objects as well. And fields are really intersections of rows and columns, so you could make row objects, column objects and intersection objects.

    I would just leave it as is. Static data is just that, static data.

      Good point(s)! A solid case of nothing to be gained— leading to a strong 'if it is not broken then don't fix it' conclusion.

      --hsm

      "Never try to teach a pig to sing...it wastes your time and it annoys the pig."
Re: Moose and static arrays
by Anonymous Monk on Jan 21, 2011 at 09:05 UTC

    What benefits would you expect from moosifying pre-declared static data?

      Good question. I must admit that I'm guilty of assuming that there are in fact some benefits to be gained. If Moose represents the direction that Perl OO is going, then it follows (I thought anyway) that this case might have a corresponding analog. Perhaps not— I don't know, that is why I ask the question.

      --hsm

      "Never try to teach a pig to sing...it wastes your time and it annoys the pig."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://883458]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-03-19 08:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found