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