my $meta = shift;
my $name = shift;
- Moose->throw_error('Usage: has \'name\' => ( key => value, ... )')
+ Moose::Util::throw('Usage: has \'name\' => ( key => value, ... )')
if @_ % 2 == 1;
my %options = ( definition_context => Moose::Util::_caller_info(), @_ );
my %args = @_;
my $class = $args{for_class}
- or Moose->throw_error("Cannot call init_meta without specifying a for_class");
+ or Moose::Util::throw("Cannot call init_meta without specifying a for_class");
my $base_class = $args{base_class} || 'Moose::Object';
my $metaclass = $args{metaclass} || 'Moose::Meta::Class';
my $meta_name = exists $args{meta_name} ? $args{meta_name} : 'meta';
- Moose->throw_error("The Metaclass $metaclass must be loaded. (Perhaps you forgot to 'use $metaclass'?)")
+ Moose::Util::throw("The Metaclass $metaclass must be loaded. (Perhaps you forgot to 'use $metaclass'?)")
unless is_class_loaded($metaclass);
- Moose->throw_error("The Metaclass $metaclass must be a subclass of Moose::Meta::Class.")
+ Moose::Util::throw("The Metaclass $metaclass must be a subclass of Moose::Meta::Class.")
unless $metaclass->isa('Moose::Meta::Class');
# make a subtype for each Moose class
unless ( $meta->isa("Moose::Meta::Class") ) {
my $error_message = "$class already has a metaclass, but it does not inherit $metaclass ($meta).";
if ( $meta->isa('Moose::Meta::Role') ) {
- Moose->throw_error($error_message . ' You cannot make the same thing a role and a class. Remove either Moose or Moose::Role.');
+ Moose::Util::throw($error_message . ' You cannot make the same thing a role and a class. Remove either Moose or Moose::Role.');
} else {
- Moose->throw_error($error_message);
+ Moose::Util::throw($error_message);
}
}
} else {
use Class::Load qw(load_class);
use List::MoreUtils qw( any uniq );
use Moose::Util::TypeConstraints;
+use Moose::Util;
use Moose::Deprecated;
requires '_helper_type';
$options->{isa} );
( $isa->is_a_type_of($type) )
- || confess
- "The type constraint for $name must be a subtype of $type but it's a $isa";
+ || Moose::Util::throw("The type constraint for $name must be a subtype of $type but it's a $isa");
}
before 'install_accessors' => sub { (shift)->_check_handles_values };
my $accessor_class = $self->_native_accessor_class_for($name);
( $accessor_class && $accessor_class->can('new') )
- || confess
- "$name is an unsupported method type - $accessor_class";
+ || Moose::Util::throw("$name is an unsupported method type - $accessor_class");
}
}
if ($self->_class_metaclass_can_be_made_compatible($super_meta)) {
($self->is_pristine)
- || confess "Can't fix metaclass incompatibility for "
+ || Moose::Util::throw("Can't fix metaclass incompatibility for "
. $self->name
- . " because it is not pristine.";
+ . " because it is not pristine.");
my $super_meta_name = $super_meta->_real_ref_name;
my $class_meta_subclass_meta_name = Moose::Util::_reconcile_roles_for_metaclass(blessed($self), $super_meta_name);
my $new_self = $class_meta_subclass_meta_name->reinitialize(
if ($self->_single_metaclass_can_be_made_compatible($super_meta, $metaclass_type)) {
($self->is_pristine)
- || confess "Can't fix metaclass incompatibility for "
+ || Moose::Util::throw("Can't fix metaclass incompatibility for "
. $self->name
- . " because it is not pristine.";
+ . " because it is not pristine.");
my $super_meta_name = $super_meta->_real_ref_name;
my $class_specific_meta_subclass_meta_name = Moose::Util::_reconcile_roles_for_metaclass($self->$metaclass_type, $super_meta->$metaclass_type);
my $new_self = $super_meta->reinitialize(
use strict;
use warnings;
-use Carp qw( confess );
use Scalar::Util qw( blessed weaken );
+use Moose::Util;
use Moose::Role;
$options{curried_arguments} = []
unless exists $options{curried_arguments};
- confess 'You must supply a curried_arguments which is an ARRAY reference'
+ Moose::Util::throw('You must supply a curried_arguments which is an ARRAY reference')
unless $options{curried_arguments}
&& ref($options{curried_arguments}) eq 'ARRAY';
use strict;
use warnings;
-use Carp 'confess';
+use Moose::Util;
use Scalar::Util 'blessed', 'weaken';
use base 'Moose::Meta::Method',
my %options = @_;
( exists $options{attribute} )
- || confess "You must supply an attribute to construct with";
+ || Moose::Util::throw "You must supply an attribute to construct with";
( blessed( $options{attribute} )
&& $options{attribute}->isa('Moose::Meta::Attribute') )
- || confess
+ || Moose::Util::throw
"You must supply an attribute which is a 'Moose::Meta::Attribute' instance";
( $options{package_name} && $options{name} )
- || confess
+ || Moose::Util::throw
"You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT";
( $options{delegate_to_method} && ( !ref $options{delegate_to_method} )
|| ( 'CODE' eq ref $options{delegate_to_method} ) )
- || confess
+ || Moose::Util::throw
'You must supply a delegate_to_method which is a method name or a CODE reference';
exists $options{curried_arguments}
( $options{curried_arguments} &&
( 'ARRAY' eq ref $options{curried_arguments} ) )
- || confess 'You must supply a curried_arguments which is an ARRAY reference';
+ || Moose::Util::throw 'You must supply a curried_arguments which is an ARRAY reference';
my $self = $class->_new( \%options );
use Class::Load qw(load_class);
use Scalar::Util 'blessed';
-use Carp 'confess';
use Devel::GlobalDestruction 'in_global_destruction';
use Moose::Meta::Class;
my %options = @args;
(ref $options{attributes} eq 'HASH')
- || confess "You must pass a HASH ref of attributes"
+ || Moose::Util::throw "You must pass a HASH ref of attributes"
if exists $options{attributes};
(ref $options{methods} eq 'HASH')
- || confess "You must pass a HASH ref of methods"
+ || Moose::Util::throw "You must pass a HASH ref of methods"
if exists $options{methods};
(ref $options{roles} eq 'ARRAY')
- || confess "You must pass an ARRAY ref of roles"
+ || Moose::Util::throw "You must pass an ARRAY ref of roles"
if exists $options{roles};
my $package = delete $options{package};
use strict;
use warnings;
-use Carp 'confess';
use List::MoreUtils 'all';
use Scalar::Util 'blessed', 'weaken';
my ( $class, $name, %options ) = @_;
(defined $name)
- || confess "You must provide a name for the attribute";
+ || Moose::Util::throw "You must provide a name for the attribute";
my $role = delete $options{_original_role};
my ( $self, $role ) = @_;
( blessed($role) && $role->isa('Moose::Meta::Role') )
- || confess
+ || Moose::Util::throw
"You must pass a Moose::Meta::Role instance (or a subclass)";
weaken( $self->{'associated_role'} = $role );
bool => sub { 1 },
fallback => 1;
-use Carp qw(confess);
use Class::Load qw(load_class);
use Eval::Closure;
use Scalar::Util qw(blessed refaddr);
if ( exists $args{message}
&& (!ref($args{message}) || ref($args{message}) ne 'CODE') ) {
- confess("The 'message' parameter must be a coderef");
+ Moose::Util::throw("The 'message' parameter must be a coderef");
}
my $self = $class->_new(%args);
use Moose::Meta::TypeConstraint::Parameterized;
use Moose::Util::TypeConstraints ();
-use Carp 'confess';
-
__PACKAGE__->meta->add_attribute('constraint_generator' => (
accessor => 'constraint_generator',
predicate => 'has_constraint_generator',
sub generate_inline_for {
my ($self, $type, $val) = @_;
- confess "Can't generate an inline constraint for $type, since none "
+ Moose::Util::throw "Can't generate an inline constraint for $type, since none "
. "was defined"
unless $self->has_inline_generator;
if (my $type = $REGISTRY->get_type_constraint($class)) {
if (!($type->isa('Moose::Meta::TypeConstraint::Class') && $type->class eq $class)) {
- _confess(
+ Moose::Util::throw(
"The type constraint '$class' has already been created in "
. $type->_package_defined_in
. " and cannot be created again in "
if (my $type = $REGISTRY->get_type_constraint($role)) {
if (!($type->isa('Moose::Meta::TypeConstraint::Role') && $type->role eq $role)) {
- _confess(
+ Moose::Util::throw(
"The type constraint '$role' has already been created in "
. $type->_package_defined_in
. " and cannot be created again in "
return $type_constraint_name;
}
-sub _confess {
- my $error = shift;
-
- local $Carp::CarpLevel = $Carp::CarpLevel + 1;
- Carp::confess($error);
-}
-
## --------------------------------------------------------
## exported functions ...
## --------------------------------------------------------
my $type = $REGISTRY->get_type_constraint($name);
( $type->_package_defined_in eq $pkg_defined_in )
- || _confess(
+ || Moose::Util::throw(
"The type constraint '$name' has already been created in "
. $type->_package_defined_in
. " and cannot be created again in "