Created
May 12, 2010 09:52
-
-
Save memowe/398401 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Duck; | |
my $duck = Duck->new({ name => 'hellangel' }); | |
print $duck->quack; | |
print $duck->quack('Wow, this rocks!'); | |
$duck->age(3); | |
print 'my duck\'s age: ' . $duck->duck_age . ' (' . $duck->age . ")\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Duck; | |
use strict; | |
use warnings; | |
use base qw( Class::Accessor ); | |
__PACKAGE__->mk_accessors(qw( name age )); | |
sub duck_age { | |
my ( $self ) = @_; | |
return $self->age * 17; | |
} | |
sub quack { | |
my ( $self, $message ) = @_; | |
return "Quack: $message\n" if defined $message; | |
return 'Hi, this is the duck ' . $self->name . "\n"; | |
} | |
!! 42; # must. return. true value | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment