I'll give a concrete example to make clear what I mean:
package FileParser; use parent qw ( Dondley::WestfieldVote::FileCollector ); sub get_data { my $s = shift; return $s->get_obj_prop('data', 'raw_data', $_[0]); } package FileCollector; sub get_obj_prop { my $s = shift; my $obj = shift; my $prop = shift; my $file = shift || $s->selected_file; # grabs the current file in +iterator if (!$prop || !$obj || !$file) { $s->_croak ("Missing arguments to get_obj_prop method" . ' at ' . (caller(0))[1] . ', line ' . (caller(0))[2] ); } my $o = $obj . '_obj'; my $object = $s->{_files}{$file}{$o}; my $attr = "_$prop"; if (! exists $object->{$attr} ) { $s->croak ("Non-existent $obj object attribute requested: '$prop'" . ' at ' . (caller(0))[1] . ', line ' . (caller(0))[2] ); } my $value = $object->{$attr}; if (ref $value eq 'ARRAY') { return @$value; } else { return $value; } } package Data.pm sub new { my $class = shift; my $data = shift; my $obj = bless { _raw_data => $data, # raw Spreadsheet::Read object _stripped_data => undef, _num_rows => undef, _cols => undef, _num_cols => undef, _non_blank_cols => undef, _first_row => undef, }, $class; return $obj; } # And finally, in a file: my $fp = FileParser->new('some/dir'); while ($fp->next_parseable_file) { my $data = $fp->get_data; }
This seems super convenient. If I'm not using an iterator, I can just pass a file to the get_data() method.
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
In reply to Re^14: How to completely destroy class attributes with Test::Most?
by nysus
in thread How to completely destroy class attributes with Test::Most?
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |