line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Role::NotSoTiny::Creator; |
3
|
|
|
|
|
|
|
$Role::NotSoTiny::Creator::VERSION = '0.1.0'; # TRIAL |
4
|
1
|
|
|
1
|
|
52220
|
use 5.010; |
|
1
|
|
|
|
|
9
|
|
5
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
6
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
303
|
use Role::NotSoTiny (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use Carp 'croak'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
86
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub create_role { |
13
|
1
|
|
|
1
|
0
|
70
|
my ( $class, $package, %args ) = @_; |
14
|
1
|
|
50
|
|
|
4
|
my $methods = $args{methods} // {}; |
15
|
1
|
|
|
|
|
7
|
Role::NotSoTiny->make_role($package); |
16
|
1
|
|
|
|
|
3
|
for my $meth ( keys %$methods ) { |
17
|
1
|
|
|
|
|
2
|
my $code = $methods->{$meth}; |
18
|
1
|
50
|
|
|
|
4
|
croak qq{Not a coderef: $meth ($code)} unless ref $code eq 'CODE'; |
19
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
20
|
1
|
|
|
|
|
2
|
*{"${package}::${meth}"} = $code; |
|
1
|
|
|
|
|
5
|
|
21
|
|
|
|
|
|
|
} |
22
|
1
|
|
|
|
|
3
|
return $package; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#pod =encoding utf8 |
28
|
|
|
|
|
|
|
#pod |
29
|
|
|
|
|
|
|
#pod =head1 NAME |
30
|
|
|
|
|
|
|
#pod |
31
|
|
|
|
|
|
|
#pod Role::NotSoTiny::Creator - Experiment with Role::Tiny / Create roles programmatically |
32
|
|
|
|
|
|
|
#pod |
33
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
34
|
|
|
|
|
|
|
#pod |
35
|
|
|
|
|
|
|
#pod use Role::NotSoTiny::Creator (); |
36
|
|
|
|
|
|
|
#pod |
37
|
|
|
|
|
|
|
#pod my $role = Role::NotSoTiny::Creator->create_role( |
38
|
|
|
|
|
|
|
#pod 'Foo', |
39
|
|
|
|
|
|
|
#pod methods => { |
40
|
|
|
|
|
|
|
#pod foo => sub {...} |
41
|
|
|
|
|
|
|
#pod }, |
42
|
|
|
|
|
|
|
#pod ); |
43
|
|
|
|
|
|
|
#pod |
44
|
|
|
|
|
|
|
#pod # runtime equivalent of |
45
|
|
|
|
|
|
|
#pod package Foo; |
46
|
|
|
|
|
|
|
#pod use Role::Tiny; |
47
|
|
|
|
|
|
|
#pod sub foo {...} |
48
|
|
|
|
|
|
|
#pod |
49
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
50
|
|
|
|
|
|
|
#pod |
51
|
|
|
|
|
|
|
#pod This module is an experiment with L. |
52
|
|
|
|
|
|
|
#pod It illustrates how the change in L makes easier |
53
|
|
|
|
|
|
|
#pod to build functionality such as a programmatic role creator. |
54
|
|
|
|
|
|
|
#pod |
55
|
|
|
|
|
|
|
#pod =head1 METHODS |
56
|
|
|
|
|
|
|
#pod |
57
|
|
|
|
|
|
|
#pod L implements the following methods. |
58
|
|
|
|
|
|
|
#pod |
59
|
|
|
|
|
|
|
#pod =head2 make_role |
60
|
|
|
|
|
|
|
#pod |
61
|
|
|
|
|
|
|
#pod Role::NotSoTiny::Creator->create_role('Some::Package', methods => \%methods); |
62
|
|
|
|
|
|
|
#pod |
63
|
|
|
|
|
|
|
#pod Prepares a given package as a role. |
64
|
|
|
|
|
|
|
#pod This is done by promoting the package to a L |
65
|
|
|
|
|
|
|
#pod and adding the given methods to its stash. |
66
|
|
|
|
|
|
|
#pod |
67
|
|
|
|
|
|
|
#pod =cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |