redo constructor class as a role too
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Role / Metaclass.pm
CommitLineData
0cdff431 1package MooseX::StrictConstructor::Role::Metaclass;
c001451a 2
3use strict;
4use warnings;
5
c001451a 6use MooseX::StrictConstructor::Meta::Method::Constructor;
7
0cdff431 8use Moose::Role;
58370717 9
64c958ef 10has 'constructor_class' =>
11 ( is => 'ro',
12 isa => 'ClassName',
13 lazy_build => 1,
14 );
c001451a 15
64c958ef 16sub _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 28around '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 40no Moose::Role;
c001451a 41
42
431;
58370717 44
45__END__
46
47=pod
48
49=head1 NAME
50
51MooseX::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
59This class simply overrides C<make_immutable()> in
60C<Moose::Meta::Class> to use
61C<MooseX::StrictConstructor::Meta::Method::Constructor> as the
62constructor class.
63
64You should never have to use this class directly.
65
66=head1 AUTHOR
67
68Dave Rolsky, C<< <autarch@urth.org> >>
69
70=head1 COPYRIGHT & LICENSE
71
72Copyright 2007 Dave Rolsky, All Rights Reserved.
73
74This program is free software; you can redistribute it and/or modify
75it under the same terms as Perl itself.
76
77=cut