Guest User

Untitled

a guest
Nov 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. package Photo;
  2. use Moose;
  3.  
  4. has 'likes' => (
  5. is => 'rw',
  6. clearer => 'unpublish',
  7. predicate => 'is_published',
  8. );
  9.  
  10. sub publish {
  11. my $self = shift;
  12. $self->likes ( 0 );
  13. }
  14.  
  15. sub like {
  16. my $self = shift;
  17.  
  18. die 'Cannot like an Unpublished photo'
  19. if ! $self->is_published;
  20.  
  21. $self->likes ( $self->likes + 1 );
  22. }
  23.  
  24.  
  25. package main;
  26.  
  27. my $profile = Photo->new;
  28. $profile->publish;
  29. $profile->like;
  30. $profile->like;
  31.  
  32. warn $profile->dump;
Add Comment
Please, Sign In to add comment