YAPC::2004::Israel | << Previous | Index | Next >> | Copyright © 2004 Gaal Yahas |
Refactoring with Class::Accessor - cont'd
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'); # ... }
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 $_"; } } |