line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Extended::Role::Custom; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Build a custom Moose::Role, just for you. |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6420
|
use 5.20.0; |
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
8
|
1
|
|
|
1
|
|
5
|
use true; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
9
|
1
|
|
|
|
|
48
|
use MooseX::Extended::Core qw( |
10
|
|
|
|
|
|
|
_enabled_features |
11
|
|
|
|
|
|
|
_disabled_warnings |
12
|
1
|
|
|
1
|
|
983
|
); |
|
1
|
|
|
|
|
2
|
|
13
|
1
|
|
|
1
|
|
442
|
use MooseX::Extended::Role (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
59
|
|
14
|
1
|
|
|
1
|
|
6
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.35'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub import { |
19
|
1
|
|
|
1
|
|
8
|
my @caller = caller(0); |
20
|
1
|
|
|
|
|
19
|
my $custom_moose = $caller[0]; # this is our custom Moose definition |
21
|
1
|
50
|
|
|
|
9
|
true->import::into($custom_moose) unless $caller[1] =~ /^\(eval/; |
22
|
1
|
|
|
|
|
1205
|
strict->import::into($custom_moose); |
23
|
1
|
|
|
|
|
188
|
warnings->import::into($custom_moose); |
24
|
1
|
|
|
|
|
172
|
namespace::autoclean->import::into($custom_moose); |
25
|
1
|
|
|
|
|
214
|
feature->import( _enabled_features() ); |
26
|
1
|
|
|
|
|
5
|
warnings->unimport(_disabled_warnings); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub create { |
30
|
1
|
|
|
1
|
0
|
231
|
my ( $class, %args ) = @_; |
31
|
1
|
|
|
|
|
4
|
my $target_class = caller(1); # this is the class consuming our custom Moose |
32
|
1
|
|
|
|
|
20
|
MooseX::Extended::Role->import( |
33
|
|
|
|
|
|
|
%args, |
34
|
|
|
|
|
|
|
call_level => 1, |
35
|
|
|
|
|
|
|
for_class => $target_class, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
__END__ |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=pod |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=encoding UTF-8 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
MooseX::Extended::Role::Custom - Build a custom Moose::Role, just for you. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 VERSION |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
version 0.35 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 SYNOPSIS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Define your own version of L<MooseX::Extended>: |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
package My::Moose::Role { |
60
|
|
|
|
|
|
|
use MooseX::Extended::Role::Custom; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub import { |
63
|
|
|
|
|
|
|
my ( $class, %args ) = @_; |
64
|
|
|
|
|
|
|
MooseX::Extended::Role::Custom->create( |
65
|
|
|
|
|
|
|
excludes => [qw/ carp /], |
66
|
|
|
|
|
|
|
includes => ['multi'], |
67
|
|
|
|
|
|
|
%args # you need this to allow customization of your customization |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# no need for a true value |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
And then use it: |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
package Some::Class::Role { |
77
|
|
|
|
|
|
|
use My::Moose::Role types => [qw/ArrayRef Num/]; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
param numbers => ( isa => ArrayRef[Num] ); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
multi sub foo ($self) { ... } |
82
|
|
|
|
|
|
|
multi sub foo ($self, $bar) { ... } |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 DESCRIPTION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
I hate boilerplate, so let's get rid of it. Let's say you don't want warnings |
88
|
|
|
|
|
|
|
on classes implicitly overriding role methods, L<namespace::autoclean> or |
89
|
|
|
|
|
|
|
C<carp>, but you do want C<multi>. Plus, you have custom versions of C<carp> |
90
|
|
|
|
|
|
|
and C<croak>: |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
package Some::Class { |
93
|
|
|
|
|
|
|
use MooseX::Extended |
94
|
|
|
|
|
|
|
excludes => [qw/ WarnOnConflict autoclean carp /], |
95
|
|
|
|
|
|
|
includes => ['multi']; |
96
|
|
|
|
|
|
|
use My::Carp q(carp croak); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
... my code here |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
You probably get tired of typing that every time. Now you don't have to. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
package My::Moose { |
104
|
|
|
|
|
|
|
use MooseX::Extended::Custom; |
105
|
|
|
|
|
|
|
use My::Carp (); |
106
|
|
|
|
|
|
|
use Import::Into; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub import { |
109
|
|
|
|
|
|
|
my ( $class, %args ) = @_; |
110
|
|
|
|
|
|
|
my $target_class = caller; |
111
|
|
|
|
|
|
|
MooseX::Extended::Custom->create( |
112
|
|
|
|
|
|
|
excludes => [qw/ autoclean carp /], |
113
|
|
|
|
|
|
|
includes => ['multi'], |
114
|
|
|
|
|
|
|
%args # you need this to allow customization of your customization |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
My::Carp->import::into($target_class, qw(carp croak)); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
And then when you use C<My::Moose>, that's all set up for you. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
If you need to change this on a "per class" basis: |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
use My::Moose |
125
|
|
|
|
|
|
|
excludes => ['carp'], |
126
|
|
|
|
|
|
|
types => [qw/ArrayRef Num/]; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
The above changes your C<excludes> and adds C<types>, but doesn't change your C<includes>. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 AUTHOR |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Curtis "Ovid" Poe <curtis.poe@gmail.com> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by Curtis "Ovid" Poe. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This is free software, licensed under: |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |