Commit | Line | Data |
0cdff431 |
1 | package MooseX::StrictConstructor::Role::Metaclass; |
c001451a |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
c001451a |
6 | use MooseX::StrictConstructor::Meta::Method::Constructor; |
7 | |
0cdff431 |
8 | use Moose::Role; |
58370717 |
9 | |
64c958ef |
10 | has 'constructor_class' => |
11 | ( is => 'ro', |
12 | isa => 'ClassName', |
13 | lazy_build => 1, |
14 | ); |
c001451a |
15 | |
64c958ef |
16 | sub _build_constructor_class |
17 | { |
18 | return |
19 | Moose::Meta::Class->create_anon_class |
20 | ( superclasses => [ 'Moose::Meta::Method::Constructor' ], |
21 | roles => [ 'MooseX::StrictConstructor::Role::Constructor' ], |
22 | cache => 1, |
23 | )->name(); |
24 | } |
25 | |
26 | # If Moose::Meta::Class had a constructor_class attribute, this |
27 | # wrapper would not be necessary. |
b210d8fb |
28 | around 'make_immutable' => sub |
58370717 |
29 | { |
eb640f6c |
30 | my $orig = shift; |
c001451a |
31 | my $self = shift; |
32 | |
33 | return |
eb640f6c |
34 | $self->$orig |
64c958ef |
35 | ( constructor_class => $self->constructor_class(), |
58370717 |
36 | @_, |
c001451a |
37 | ); |
58370717 |
38 | }; |
39 | |
0cdff431 |
40 | no Moose::Role; |
c001451a |
41 | |
42 | |
43 | 1; |
58370717 |
44 | |
45 | __END__ |
46 | |
47 | =pod |
48 | |
49 | =head1 NAME |
50 | |
51 | MooseX::StrictConstructor::Meta::Class - A meta class for classes with strict constructors |
52 | |
53 | =head1 SYNOPSIS |
54 | |
55 | use MooseX::StrictConstructor; |
56 | |
57 | =head1 DESCRIPTION |
58 | |
59 | This class simply overrides C<make_immutable()> in |
60 | C<Moose::Meta::Class> to use |
61 | C<MooseX::StrictConstructor::Meta::Method::Constructor> as the |
62 | constructor class. |
63 | |
64 | You should never have to use this class directly. |
65 | |
66 | =head1 AUTHOR |
67 | |
68 | Dave Rolsky, C<< <autarch@urth.org> >> |
69 | |
70 | =head1 COPYRIGHT & LICENSE |
71 | |
72 | Copyright 2007 Dave Rolsky, All Rights Reserved. |
73 | |
74 | This program is free software; you can redistribute it and/or modify |
75 | it under the same terms as Perl itself. |
76 | |
77 | =cut |