Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / i486-linux-gnu-thread-multi / MooseX / Role / WithOverloading.pm
1 package MooseX::Role::WithOverloading;
2 our $VERSION = '0.03';
3
4
5 # ABSTRACT: Roles which support overloading
6
7 use XSLoader;
8 use Moose::Role ();
9 use Moose::Exporter;
10 use Moose::Util::MetaRole;
11 use aliased 'MooseX::Role::WithOverloading::Meta::Role', 'MetaRole';
12 use aliased 'MooseX::Role::WithOverloading::Meta::Role::Application::ToClass';
13 use aliased 'MooseX::Role::WithOverloading::Meta::Role::Application::ToRole';
14 use aliased 'MooseX::Role::WithOverloading::Meta::Role::Application::ToInstance';
15
16 use namespace::clean;
17
18 XSLoader::load(__PACKAGE__, $VERSION);
19
20 Moose::Exporter->setup_import_methods(also => 'Moose::Role');
21
22 sub 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
35 1;
36
37
38 __END__
39 =pod
40
41 =head1 NAME
42
43 MooseX::Role::WithOverloading - Roles which support overloading
44
45 =head1 VERSION
46
47 version 0.03
48
49 =head1 SYNOPSIS
50
51     package MyRole;
52 our $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;
69 our $VERSION = '0.03';
70
71
72     use Moose;
73     use namespace::autoclean;
74
75     with 'MyRole';
76
77     package main;
78 our $VERSION = '0.03';
79
80
81
82     my $i = MyClass->new( message => 'foobar' );
83     print $i; # Prints 'foobar'
84
85 =head1 DESCRIPTION
86
87 MooseX::Role::WithOverloading allows you to write a L<Moose::Role> which
88 defines overloaded operators and allows those operator overloadings to be
89 composed into the classes/roles/instances it's compiled to, while plain
90 L<Moose::Role>s would lose the overloading.
91
92 =for Pod::Coverage init_meta
93
94 =head1 AUTHORS
95
96 Florian Ragwitz <rafl@debian.org>
97 Tomas Doran <bobtfish@bobtfish.net>
98
99 =head1 COPYRIGHT AND LICENSE
100
101 This software is copyright (c) 2009 by Florian Ragwitz.
102
103 This is free software; you can redistribute it and/or modify it under
104 the same terms as the Perl 5 programming language system itself.
105
106 =cut
107