Created
July 2, 2012 06:32
-
-
Save ynonp/3031451 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Photo; | |
use Moose; | |
has 'likes' => ( | |
is => 'rw', | |
clearer => 'unpublish', | |
predicate => 'is_published', | |
); | |
sub publish { | |
my $self = shift; | |
$self->likes ( 0 ); | |
} | |
sub like { | |
my $self = shift; | |
die 'Cannot like an Unpublished photo' | |
if ! $self->is_published; | |
$self->likes ( $self->likes + 1 ); | |
} | |
package main; | |
my $profile = Photo->new; | |
$profile->publish; | |
$profile->like; | |
$profile->like; | |
warn $profile->dump; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment