Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
Add Comment
Please, Sign In to add comment