Simply loading this module makes your constructors "strict". If your
constructor is called with an attribute init argument that your class
-does not declare, then it calls "Carp::confess()". This is a great way
+does not declare, then it calls C<Moose->throw_error()>. This is a great way
to catch small typos.
=head2 Subverting Strictness
my @bad = sort grep { !$attrs{$_} } keys %{$params};
if (@bad) {
- confess
- "Found unknown attribute(s) init_arg passed to the constructor: @bad";
+ Moose->throw_error(
+ "Found unknown attribute(s) init_arg passed to the constructor: @bad");
}
return;
use namespace::autoclean;
use B ();
-use Carp ();
around '_inline_BUILDALL' => sub {
my $orig = shift;
'my %attrs = (' . ( join ' ', @attrs ) . ');',
'my @bad = sort grep { !$attrs{$_} } keys %{ $params };',
'if (@bad) {',
- 'Carp::confess "Found unknown attribute(s) passed to the constructor: @bad";',
+ 'Moose->throw_error("Found unknown attribute(s) passed to the constructor: @bad");',
'}',
);
};
use namespace::autoclean;
use B ();
-use Carp ();
around '_generate_BUILDALL' => sub {
my $orig = shift;
my \@bad = sort grep { ! \$attrs{\$_} } keys \%{ \$params };
if (\@bad) {
- Carp::confess "Found unknown attribute(s) passed to the constructor: \@bad";
+ Moose->throw_error("Found unknown attribute(s) passed to the constructor: \@bad");
}
EOF