Made it work with immutable classes.
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / Object / StrictConstructor.pm
CommitLineData
32726d88 1package MooseX::Object::StrictConstructor;
2
3use strict;
4use warnings;
5
6use Moose;
7
8use Carp 'confess';
9
c001451a 10use metaclass 'MooseX::StrictConstructor::Meta::Class';
11
12
32726d88 13extends 'Moose::Object';
14
15after 'BUILDALL' => sub
16{
17 my $self = shift;
18 my $params = shift;
19
20 my %attrs = map { $_->name() => 1 } $self->meta()->compute_all_applicable_attributes();
21
d692165d 22 my @bad = sort grep { ! $attrs{$_} } keys %{ $params };
32726d88 23
24 if (@bad)
25 {
26 confess "Found unknown attribute(s) passed to the constructor: @bad";
27 }
28
29 return;
30};
31
32
331;
2ffa7b60 34
35__END__
36
37=pod
38
39=head1 NAME
40
41MooseX::Object::StrictConstructor - Implements strict constructors as a Moose::Object subclass
42
43=head1 DESCRIPTION
44
45This class has no external interface. When you use
46C<MooseX::StrictConstructor>, your objects will subclass this class
47rather than Moose::Object.
48
49=head1 AUTHOR
50
51Dave Rolsky, C<< <autarch@urth.org> >>
52
53=head1 COPYRIGHT & LICENSE
54
55Copyright 2007 Dave Rolsky, All Rights Reserved.
56
57This program is free software; you can redistribute it and/or modify
58it under the same terms as Perl itself.
59
60=cut