line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Role::WithOverloading; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
4
|
|
|
4
|
|
167047
|
$MooseX::Role::WithOverloading::AUTHORITY = 'cpan:FLORA'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# git description: v0.14-9-gae3b660 |
6
|
|
|
|
|
|
|
$MooseX::Role::WithOverloading::VERSION = '0.15'; |
7
|
|
|
|
|
|
|
# ABSTRACT: Roles which support overloading |
8
|
|
|
|
|
|
|
# KEYWORDS: moose extension role operator overload overloading |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
8046
|
use Moose::Role (); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Moose::Exporter; |
12
|
|
|
|
|
|
|
use aliased 'MooseX::Role::WithOverloading::Meta::Role', 'MetaRole'; |
13
|
|
|
|
|
|
|
use aliased 'MooseX::Role::WithOverloading::Meta::Role::Application::ToClass'; |
14
|
|
|
|
|
|
|
use aliased 'MooseX::Role::WithOverloading::Meta::Role::Application::ToRole'; |
15
|
|
|
|
|
|
|
use aliased 'MooseX::Role::WithOverloading::Meta::Role::Application::ToInstance'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use namespace::clean; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# this functionality is built-in, starting with Moose 2.1300 |
20
|
|
|
|
|
|
|
my $has_core_support = eval { Moose->VERSION('2.1300'); 1 }; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
if ($has_core_support) |
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
Moose::Exporter->setup_import_methods(also => 'Moose::Role'); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
require XSLoader; |
29
|
|
|
|
|
|
|
XSLoader::load( |
30
|
|
|
|
|
|
|
__PACKAGE__, |
31
|
|
|
|
|
|
|
$MooseX::Role::WithOverloading::{VERSION} |
32
|
|
|
|
|
|
|
? ${ $MooseX::Role::WithOverloading::{VERSION} } |
33
|
|
|
|
|
|
|
: () |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Moose::Exporter->setup_import_methods( |
37
|
|
|
|
|
|
|
also => 'Moose::Role', |
38
|
|
|
|
|
|
|
role_metaroles => { |
39
|
|
|
|
|
|
|
role => [MetaRole], |
40
|
|
|
|
|
|
|
application_to_class => [ToClass], |
41
|
|
|
|
|
|
|
application_to_role => [ToRole], |
42
|
|
|
|
|
|
|
application_to_instance => [ToInstance], |
43
|
|
|
|
|
|
|
}, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=pod |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=encoding UTF-8 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
MooseX::Role::WithOverloading - Roles which support overloading |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 VERSION |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
version 0.15 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 SYNOPSIS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
package MyRole; |
66
|
|
|
|
|
|
|
use MooseX::Role::WithOverloading; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use overload |
69
|
|
|
|
|
|
|
q{""} => 'as_string', |
70
|
|
|
|
|
|
|
fallback => 1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
has message => ( |
73
|
|
|
|
|
|
|
is => 'rw', |
74
|
|
|
|
|
|
|
isa => 'Str', |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub as_string { shift->message } |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
package MyClass; |
80
|
|
|
|
|
|
|
use Moose; |
81
|
|
|
|
|
|
|
use namespace::autoclean; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
with 'MyRole'; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
package main; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $i = MyClass->new( message => 'foobar' ); |
88
|
|
|
|
|
|
|
print $i; # Prints 'foobar' |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
MooseX::Role::WithOverloading allows you to write a L<Moose::Role> which |
93
|
|
|
|
|
|
|
defines overloaded operators and allows those overload methods to be |
94
|
|
|
|
|
|
|
composed into the classes/roles/instances it's compiled to, where plain |
95
|
|
|
|
|
|
|
L<Moose::Role>s would lose the overloading. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Starting with L<Moose> version 2.1300, this module is no longer necessary, as |
98
|
|
|
|
|
|
|
the functionality is available already. In that case, |
99
|
|
|
|
|
|
|
C<use MooseX::Role::WithOverloading> behaves identically to C<use Moose::Role>. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=for stopwords metaclasses |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 AUTHORS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=over 4 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item * |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Tomas Doran <bobtfish@bobtfish.net> |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=back |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This software is copyright (c) 2009 by Florian Ragwitz. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
122
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=for stopwords Dave Rolsky Florian Ragwitz Jesse Luehrs Tomas Doran (t0m) |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=over 4 |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Jesse Luehrs <doy@tozt.net> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Tomas Doran (t0m) <t0m@state51.co.uk> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Tomas Doran <bobtfish@bobtfish.net> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=back |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |