Why Subclass at All?

Each Data::Presenter subclass holds subroutines which are fine-tuned to the messy details of parsing data from the database which the subclass is designed to handle.

&Data::Presenter::new
  sub new {
    ...
    $self = bless {}, ref($class) || $class;
    ...
    $dataref = $self->_init(
        $source, $fieldsref, $paramsref, $index, \%reserved);
    ...
    %$self = %$dataref;
    return $self;
  }
&Data::Presenter::SampleCensus::_init
  sub _init {
    ($self, $sourcefile, $fieldsref, $paramsref, $index) = @_;
    %data = ();
    $data{'fields'} = $fieldsref;
    $data{'parameters'} = $paramsref;
    $data{'index'} = [$index];
    ... # DATA MUNGING
    $data{$corrected[$index]} = \@corrected;
    return \%data;
  }

Previous Back to start of show Next
Slide: 38 why_subclass © 2003 James E. Keenan