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,In test.pl,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;
If you run test.pl you should see a dump of your data structure.#!/usr/bin/env perl use DataDecoder; my $dd = DataDecoder->new(); my @array = @{$dd->parserArray_type_01_ref}; use Data::Dumper; print Dumper @array; exit;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |