Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Binary data structure to moose class.

by chrestomanci (Priest)
on Jan 04, 2013 at 17:34 UTC ( #1011686=note: print w/ replies, xml ) Need Help??


in reply to Re: Binary data structure to moose class.
in thread Binary data structure to moose class.

Thanks jandrew For the tip on using triggers. It is certainly a step in the right direction as it will allow me to move all the binary unpacking code into one method, that will populate all the fields in the class at once.

For my project, I am only relay interested in reading binary data, not writing it. If I where trying to write it as well, then I am not sure that using writers would be helpful, as it looks like that will just create the same problem of lots of very similar methods with very similar boilerplate code. I think an easier approach would be to create a custom reader method on rawDataBlock that will re-construct the binary data by packing all the field members.

Also, thanks for the link to merlyn's tutorials. I will certainly read them. One problem I have with Moose is there is too much documentation, and it can be hard to find a simplified introduction.


Comment on Re^2: Binary data structure to moose class.
Re^3: Binary data structure to moose class.
by jandrew (Hermit) on Jan 04, 2013 at 18:22 UTC

    chrestomanci I personally found that a combination of the Moose::Cookbook followed with a good dose of the Moose::Manual was the most concise way to kick-start my Moose learning. However the Moose presentation from Ricardo Signes is a good read. I'm at $work so I can't check that last link.

    The goal of the writers is not to write binary data in the attributes but to write the unpacked data to each attribute from the object so you can use it as follows. (Note the writers are mostly hidden using the _ prefix convention) Assume the Class is called Data::Humanx and that the MooseX::Types coersion worked. Example not tested

    use Data::Humanx my $instance = Data::Humanx-new( rawDataBlock => $content ); print $instance->startTime->ymd( '/' );

    This should print out the start time value in ymd format from the Humanx binary that was input. (This assumes a DateTime object in the startTime attribute)

    Update: The link is good

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011686]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-10-24 21:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (137 votes), past polls