Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. package My::Role;
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use Moose::Role;
  7. use MooseX::ClassAttribute;
  8.  
  9. class_has table => (
  10. is => 'ro'
  11. isa => 'Str',
  12. lazy => 1,
  13. );
  14.  
  15. has id => (
  16. is => 'ro',
  17. isa => 'Int',
  18. predicate => 'has_id',
  19. writer => '_id',
  20. required => 0,
  21. );
  22.  
  23. has other => (
  24. is => 'rw',
  25. isa => 'Int',
  26. );
  27.  
  28. ...
  29.  
  30. 1;
  31.  
  32. package Some::Module;
  33.  
  34. with 'My::Role' => {
  35. -excludes => [qw( id table )]
  36. };
  37.  
  38. has module_id => (
  39. is => 'ro',
  40. isa => 'Int',
  41. );
  42. ...
  43.  
  44. 1;
  45.  
  46. my $some_module = Some::Module->new({ other => 3 });
  47.  
  48. $some_module->id; # I'd expect this to die but returns undef.
  49.  
  50. $some_module->table; # this dies as I'd expect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement