YAPC::2004::Israel << Previous | Index | Next >> Copyright © 2004 Gaal Yahas

Refactoring with Class::Accessor - cont'd


  • now, we have our pretty flow function (in rather less than 500 lines), with assertion points, too:

     sub process_job {
         my $job = shift;
         $job->assert_populated('job_spec');
         $job->discover_customer_information();
         $job->assert_populated('cust');
         $job->calulate_extra_job_info();
         $job->assert_populated('job');
         # ...
     }
  • here's assert_populated():

     sub assert_populated {
        my($job, $spec) = @_;
        my $fields = $job->FIELDS()->{$spec} or die "no such spec";
        foreach (@$fields) {
            defined $job->get($_) or die "missing required field $_";
        }
     }