I'm not sure I completely understand your question, but do you just want an attribute that contains your data structure? If so, you can do something like this...

In DataDecoder.pm,
package DataDecoder; use Moose; has 'parserArray_type_01_ref' => ( is => 'ro', isa => 'ArrayRef', builder => 'get_type_01_ref', lazy => 1 ); sub get_type_01_ref { my $array_ref = [ { name => 'YEAR', type => 'CHAR', len => 2, description => sub{0} }, { name => 'MONTH', type => 'CHAR', len => 2, description => sub{0} }, { name => 'DAY', type => 'CHAR', len => 2, description => sub{0} }, { name => 'HOUR', type => 'CHAR', len => 2, description => sub{0} }, { name => sub{ my $data = uc shift; my %SUD_DATA = ('98' => 'TYPE1', '64' => 'TYPE2'); (defined $SUD_DATA{$data})? $SUD_DATA{$data} : $data # $data }, type => 'HEX', len => 1, description => sub{ my $data = uc shift; my %SUD_DATA = ('98' => 'TYPE1', '64' => 'TYPE2'); (defined $SUD_DATA{$data})? $SUD_DATA{$data} : $data # $data }, } ]; return $array_ref; } 1;
In test.pl,
#!/usr/bin/env perl use DataDecoder; my $dd = DataDecoder->new(); my @array = @{$dd->parserArray_type_01_ref}; use Data::Dumper; print Dumper @array; exit;
If you run test.pl you should see a dump of your data structure.

Take a look at Moose::Manual::Attributes and Moose::Manual::BestPracties for more information.


In reply to Re: defined class variable with Moose by kevbot
in thread defined class variable with Moose by Hosen1989

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.