Help for this page

Select Code to Download


  1. or download this
    sub name {
       my $self = shift;
    ...
       }
       return $self->{name};
    }
    
  2. or download this
    sub name   { $_[0]->{name}   //= $_[0]->_build_name }
    sub colour { $_[0]->{colour} //= $_[0]->_build_colour }
    sub owner  { $_[0]->{owner} }           # this one has no default
    sub height { $_[0]->{height} //= 2.5 }  # another way to provide a def
    +ault
    ...;
    
  3. or download this
    my $aj      = Horse->new(name => "Applejack");
    my $metres  = $aj->height( in => "metres" );
    my $inches  = $aj->height( in => "inches" );
    my $hands   = $aj->height( in => "hands" );
    my $silly   = $aj->height( in => "lightyears" );