Created
April 23, 2016 22:14
-
-
Save semifor/2e2ee2b9e78aa932fbec7d4923996f32 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
| #!/usr/bin/env perl | |
| use 5.14.1; | |
| use warnings; | |
| package API { | |
| use Moose::Role; | |
| requires qw/store/; | |
| } | |
| package IntervalUsers { | |
| use Moose::Role; | |
| requires qw/chart_type interval_users/; | |
| sub store {} | |
| } | |
| package Age { | |
| use Moose::Role; | |
| requires qw/age_from_user/; | |
| # If I use an attribute, it fails the requires check. If I use a method, it succeeds. | |
| # The documentation says: | |
| # > Note that attribute accessors also count as methods for the purposes of | |
| # > satisfying the requirements of a role. | |
| sub interval_users {} | |
| #has interval_users => ( is => 'ro' ); | |
| with qw/IntervalUsers/; | |
| } | |
| package AccountAges { | |
| use Moose; | |
| with qw/Age API/; | |
| sub chart_type () { 'age' } | |
| sub age_from_user {} | |
| } | |
| my $component = AccountAges->new; | |
| say $component->store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment