Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created July 2, 2012 06:32
Show Gist options
  • Save ynonp/3031451 to your computer and use it in GitHub Desktop.
Save ynonp/3031451 to your computer and use it in GitHub Desktop.
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