X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStrictConstructor%2FRole%2FObject.pm;fp=lib%2FMooseX%2FStrictConstructor%2FRole%2FObject.pm;h=cefb3427e2faa46164cc2594e8efbfa2af0d6b64;hb=0cdff4316fbe5eff66d9649dc85d42eefc91f29a;hp=0000000000000000000000000000000000000000;hpb=c94bcaec88348ee09f259bf1bc68a7dbe2689dcc;p=gitmo%2FMooseX-StrictConstructor.git diff --git a/lib/MooseX/StrictConstructor/Role/Object.pm b/lib/MooseX/StrictConstructor/Role/Object.pm new file mode 100644 index 0000000..cefb342 --- /dev/null +++ b/lib/MooseX/StrictConstructor/Role/Object.pm @@ -0,0 +1,60 @@ +package MooseX::StrictConstructor::Role::Object; + +use strict; +use warnings; + +use Moose::Role; + + +after 'BUILDALL' => sub +{ + my $self = shift; + my $params = shift; + + my %attrs = + ( map { $_ => 1 } + grep { defined } + map { $_->init_arg() } + $self->meta()->compute_all_applicable_attributes() + ); + + my @bad = sort grep { ! $attrs{$_} } keys %{ $params }; + + if (@bad) + { + confess "Found unknown attribute(s) init_arg passed to the constructor: @bad"; + } + + return; +}; + +no Moose::Role; + +1; + +__END__ + +=pod + +=head1 NAME + +MooseX::Object::StrictConstructor - Implements strict constructors as a Moose::Object subclass + +=head1 DESCRIPTION + +This class has no external interface. When you use +C, your objects will subclass this class +rather than Moose::Object. + +=head1 AUTHOR + +Dave Rolsky, C<< >> + +=head1 COPYRIGHT & LICENSE + +Copyright 2007 Dave Rolsky, All Rights Reserved. + +This program is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut