Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / i486-linux-gnu-thread-multi / MooseX / Role / WithOverloading.pm
CommitLineData
3fea05b9 1package MooseX::Role::WithOverloading;
2our $VERSION = '0.03';
3
4
5# ABSTRACT: Roles which support overloading
6
7use XSLoader;
8use Moose::Role ();
9use Moose::Exporter;
10use Moose::Util::MetaRole;
11use aliased 'MooseX::Role::WithOverloading::Meta::Role', 'MetaRole';
12use aliased 'MooseX::Role::WithOverloading::Meta::Role::Application::ToClass';
13use aliased 'MooseX::Role::WithOverloading::Meta::Role::Application::ToRole';
14use aliased 'MooseX::Role::WithOverloading::Meta::Role::Application::ToInstance';
15
16use namespace::clean;
17
18XSLoader::load(__PACKAGE__, $VERSION);
19
20Moose::Exporter->setup_import_methods(also => 'Moose::Role');
21
22sub init_meta {
23 my ($class, %opts) = @_;
24 my $meta = Moose::Role->init_meta(%opts);
25
26 return Moose::Util::MetaRole::apply_metaclass_roles(
27 for_class => $meta,
28 metaclass_roles => [ MetaRole ],
29 application_to_class_class_roles => [ ToClass ],
30 application_to_role_class_roles => [ ToRole ],
31 application_to_instance_class_roles => [ ToInstance ],
32 );
33}
34
351;
36
37
38__END__
39=pod
40
41=head1 NAME
42
43MooseX::Role::WithOverloading - Roles which support overloading
44
45=head1 VERSION
46
47version 0.03
48
49=head1 SYNOPSIS
50
51 package MyRole;
52our $VERSION = '0.03';
53
54
55 use MooseX::Role::WithOverloading;
56
57 use overload
58 q{""} => 'as_string',
59 fallback => 1;
60
61 has message => (
62 is => 'rw',
63 isa => 'Str',
64 );
65
66 sub as_string { shift->message }
67
68 package MyClass;
69our $VERSION = '0.03';
70
71
72 use Moose;
73 use namespace::autoclean;
74
75 with 'MyRole';
76
77 package main;
78our $VERSION = '0.03';
79
80
81
82 my $i = MyClass->new( message => 'foobar' );
83 print $i; # Prints 'foobar'
84
85=head1 DESCRIPTION
86
87MooseX::Role::WithOverloading allows you to write a L<Moose::Role> which
88defines overloaded operators and allows those operator overloadings to be
89composed into the classes/roles/instances it's compiled to, while plain
90L<Moose::Role>s would lose the overloading.
91
92=for Pod::Coverage init_meta
93
94=head1 AUTHORS
95
96Florian Ragwitz <rafl@debian.org>
97Tomas Doran <bobtfish@bobtfish.net>
98
99=head1 COPYRIGHT AND LICENSE
100
101This software is copyright (c) 2009 by Florian Ragwitz.
102
103This is free software; you can redistribute it and/or modify it under
104the same terms as the Perl 5 programming language system itself.
105
106=cut
107