[Previous] [Contents] [Next]


Listing 2.8. Overriding Customers methods.


package MyCust;

 require Customer; # requires Customer.pm from Listing 2.4

 @ISA = qw(Customer);



 sub search{

 my $self = shift;

 my $key = shift;

 defined($self->{$key}) ? return $self->{$key} : undef;

 }



 sub dumpcust{

 my $self = shift;

 # Print out _all_ the values for the object

 foreach $key (keys %{$self}){

     if($key eq `Vitals'){

         print join(` `,@{$self->{$key}}),"\n";

     }

     else{

         print $self->{$key},"\n";

     }

 }

 }

 1;


Now you can invoke the dumpcust() method within the MyCust class and get the behavior you want, having all the fields print. (Note that Listing 2.9 requires the code from both Listing 2.4 and 2.8.)

[Previous] [Contents] [Next]