_apply_meta_traits( $CALLER, $traits );
}
elsif ( @{$traits} ) {
+ require Moose;
Moose->throw_error(
"Cannot provide traits when $class does not have an init_meta() method"
);
# this was changed in 0.41, but broke MooseX::Singleton, so try to catch
# any other code using the original broken spelling
-sub intialize_body { Moose->throw_error("Please correct the spelling of 'intialize_body' to 'initialize_body'") }
+sub intialize_body { $_[0]->throw_error("Please correct the spelling of 'intialize_body' to 'initialize_body'") }
sub initialize_body {
my $self = shift;
sub add_attribute {
my $self = shift;
my $name = shift;
- (defined $name && $name)
- || Moose->throw_error("You must provide a name for the attribute");
+ unless ( defined $name && $name ) {
+ require Moose;
+ Moose->throw_error("You must provide a name for the attribute");
+ }
my $attr_desc;
if (scalar @_ == 1 && ref($_[0]) eq 'HASH') {
$attr_desc = $_[0];
next unless $role->does_role($excluded);
my @excluding = @{ $excluded_roles{$excluded} };
+
+ require Moose;
Moose->throw_error(sprintf "Conflict detected: Role%s %s exclude%s role '%s'", (@excluding == 1 ? '' : 's'), join(', ', @excluding), (@excluding == 1 ? 's' : ''), $excluded);
}
}
my %seen;
foreach my $attr (@all_attributes) {
if (exists $seen{$attr->{name}}) {
- Moose->throw_error("We have encountered an attribute conflict with '" . $attr->{name} . "' "
- . "during composition. This is fatal error and cannot be disambiguated.")
- if $seen{$attr->{name}} != $attr->{attr};
+ if ( $seen{$attr->{name}} != $attr->{attr} ) {
+ require Moose;
+ Moose->throw_error("We have encountered an attribute conflict with '" . $attr->{name} . "' "
+ . "during composition. This is fatal error and cannot be disambiguated.")
+ }
}
$seen{$attr->{name}} = $attr->{attr};
}
my %seen;
foreach my $override (@all_overrides) {
- Moose->throw_error( "Role '" . $c->name . "' has encountered an 'override' method conflict " .
- "during composition (A local method of the same name as been found). This " .
- "is fatal error." )
- if $c->has_method($override->{name});
+ if ( $c->has_method($override->{name}) ){
+ require Moose;
+ Moose->throw_error( "Role '" . $c->name . "' has encountered an 'override' method conflict " .
+ "during composition (A local method of the same name as been found). This " .
+ "is fatal error." )
+ }
if (exists $seen{$override->{name}}) {
- Moose->throw_error( "We have encountered an 'override' method conflict during " .
- "composition (Two 'override' methods of the same name encountered). " .
- "This is fatal error.")
- if $seen{$override->{name}} != $override->{method};
+ if ( $seen{$override->{name}} != $override->{method} ) {
+ require Moose;
+ Moose->throw_error( "We have encountered an 'override' method conflict during " .
+ "composition (Two 'override' methods of the same name encountered). " .
+ "This is fatal error.")
+ }
}
$seen{$override->{name}} = $override->{method};
}
sub check_role_exclusions {
my ($self, $role1, $role2) = @_;
- Moose->throw_error("Conflict detected: " . $role2->name . " excludes role '" . $role1->name . "'")
- if $role2->excludes_role($role1->name);
+ if ( $role2->excludes_role($role1->name) ) {
+ require Moose;
+ Moose->throw_error("Conflict detected: " . $role2->name . " excludes role '" . $role1->name . "'");
+ }
foreach my $excluded_role_name ($role1->get_excluded_roles_list) {
- Moose->throw_error("The class " . $role2->name . " does the excluded role '$excluded_role_name'")
- if $role2->does_role($excluded_role_name);
+ if ( $role2->does_role($excluded_role_name) ) {
+ require Moose;
+ Moose->throw_error("The class " . $role2->name . " does the excluded role '$excluded_role_name'");
+ }
$role2->add_excluded_roles($excluded_role_name);
}
}
if ($role2->has_attribute($attribute_name) &&
# make sure we haven't seen this one already too
$role2->get_attribute($attribute_name) != $role1->get_attribute($attribute_name)) {
+
+ require Moose;
Moose->throw_error("Role '" . $role1->name . "' has encountered an attribute conflict " .
"during composition. This is fatal error and cannot be disambiguated.");
}
if ($role2->has_method($aliased_method_name) &&
# and if they are not the same thing ...
$role2->get_method($aliased_method_name)->body != $role1->get_method($method_name)->body) {
+
+ require Moose;
Moose->throw_error("Cannot create a method alias if a local method of the same name exists");
}
# we have a conflict here, because you cannot
# combine an overridden method with a locally
# defined one
+ require Moose;
Moose->throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " .
"during composition (A local method of the same name as been found). This " .
"is fatal error.");
# we are composing into
if ($role2->has_override_method_modifier($method_name) &&
$role2->get_override_method_modifier($method_name) != $role2->get_override_method_modifier($method_name)) {
+
+ require Moose;
Moose->throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " .
"during composition (Two 'override' methods of the same name encountered). " .
"This is fatal error.");
sub new {
my ($class, %params) = @_;
# the roles param is required ...
- ($_->isa('Moose::Meta::Role'))
- || Moose->throw_error("The list of roles must be instances of Moose::Meta::Role, not $_")
- foreach @{$params{roles}};
+ foreach ( @{$params{roles}} ) {
+ unless ( $_->isa('Moose::Meta::Role') ) {
+ require Moose;
+ Moose->throw_error("The list of roles must be instances of Moose::Meta::Role, not $_");
+ }
+ }
# and the name is created from the
# roles if one has not been provided
$params{name} ||= (join "|" => map { $_->name } @{$params{roles}});
# add the symbol.
sub add_method {
my ($self, $method_name, $method) = @_;
- (defined $method_name && $method_name)
- || Moose->throw_error("You must define a method name");
+
+ unless ( defined $method_name && $method_name ) {
+ Moose->throw_error("You must define a method name");
+ }
my $body;
if (blessed($method)) {
while (@coercion_map) {
my ($constraint_name, $action) = splice(@coercion_map, 0, 2);
my $type_constraint = ref $constraint_name ? $constraint_name : Moose::Util::TypeConstraints::find_or_parse_type_constraint($constraint_name);
- (defined $type_constraint)
- || Moose->throw_error("Could not find the type constraint ($constraint_name) to coerce from");
+
+ unless ( defined $type_constraint ) {
+ require Moose;
+ Moose->throw_error("Could not find the type constraint ($constraint_name) to coerce from");
+ }
+
push @coercions => [
$type_constraint->_compiled_type_constraint,
$action
while (@new_coercion_map) {
my ($constraint_name, $action) = splice(@new_coercion_map, 0, 2);
-
- Moose->throw_error("A coercion action already exists for '$constraint_name'")
- if exists $has_coercion{$constraint_name};
-
+
+ if ( exists $has_coercion{$constraint_name} ) {
+ require Moose;
+ Moose->throw_error("A coercion action already exists for '$constraint_name'")
+ }
+
push @{$coercion_map} => ($constraint_name, $action);
}
sub has_coercion_for_type { 0 }
sub add_type_coercions {
+ require Moose;
Moose->throw_error("Cannot add additional type coercions to Union types");
}
accessor => 'coercion',
predicate => 'has_coercion'
));
+
__PACKAGE__->meta->add_attribute('hand_optimized_type_constraint' => (
init_arg => 'optimized',
accessor => 'hand_optimized_type_constraint',
my ($first, @rest) = @_;
my %args = ref $first ? %$first : $first ? ($first, @rest) : ();
$args{name} = $args{name} ? "$args{name}" : "__ANON__";
-
+
my $self = $class->_new(%args);
$self->compile_type_constraint()
unless $self->_has_compiled_type_constraint;
-sub coerce { ((shift)->coercion || Moose->throw_error("Cannot coerce without a type coercion"))->coerce(@_) }
+sub coerce {
+ my $self = shift;
+
+ my $coercion = $self->coercion;
+
+ unless ($coercion) {
+ require Moose;
+ Moose->throw_error("Cannot coerce without a type coercion");
+ }
+
+ return $coercion->coerce(@_);
+}
sub check {
my ($self, @args) = @_;
if $self->has_hand_optimized_type_constraint;
my $check = $self->constraint;
- (defined $check)
- || Moose->throw_error("Could not compile type constraint '"
+ unless ( defined $check ) {
+ require Moose;
+ Moose->throw_error( "Could not compile type constraint '"
. $self->name
- . "' because no constraint check");
+ . "' because no constraint check" );
+ }
return $self->_compile_subtype($check)
if $self->has_parent;
my $type_constraint = $self->hand_optimized_type_constraint;
- Moose->throw_error("Hand optimized type constraint is not a code reference") unless ref $type_constraint;
+ unless ( ref $type_constraint ) {
+ require Moose;
+ Carp::confess ("Hand optimized type constraint for " . $self->name . " is not a code reference");
+ Moose->throw_error("Hand optimized type constraint is not a code reference");
+ }
return $type_constraint;
}
if(my $parent = $self->parent) {
if($parent->can('type_parameter')) {
- $contained_tc->is_a_type_of($parent->type_parameter)
- || Moose->throw_error("$type_parameter is not a subtype of ".$parent->type_parameter);
+ unless ( $contained_tc->is_a_type_of($parent->type_parameter) ) {
+ require Moose;
+ Moose->throw_error("$type_parameter is not a subtype of ".$parent->type_parameter);
+ }
}
}
);
}
else {
+ require Moose;
Moose->throw_error("The type parameter must be a Moose meta type");
}
}
sub compile_type_constraint {
my $self = shift;
- ($self->has_type_parameter)
- || Moose->throw_error("You cannot create a Higher Order type without a type parameter");
-
+ unless ( $self->has_type_parameter ) {
+ require Moose;
+ Moose->throw_error("You cannot create a Higher Order type without a type parameter");
+ }
+
my $type_parameter = $self->type_parameter;
- (blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint'))
- || Moose->throw_error("The type parameter must be a Moose meta type");
+ unless ( blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint') ) {
+ require Moose;
+ Moose->throw_error("The type parameter must be a Moose meta type");
+ }
foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
if (my $constraint = $type->generate_constraint_for($self)) {
# if we get here, then we couldn't
# find a way to parameterize this type
+ require Moose;
Moose->throw_error("The " . $self->name . " constraint cannot be used, because "
. $self->parent->name . " doesn't subtype or coerce from a parameterizable type.");
}
use metaclass;
use Scalar::Util 'blessed';
-use Carp 'confess'; # FIXME Moose->throw_error
our $VERSION = '0.71';
$VERSION = eval $VERSION;
sub add_type_constraint {
my ($self, $type) = @_;
- confess("No type supplied / type is not a valid type constraint")
- unless ($type && blessed $type && $type->isa('Moose::Meta::TypeConstraint'));
+
+ unless ( $type && blessed $type && $type->isa('Moose::Meta::TypeConstraint') ) {
+ require Moose;
+ Moose->throw_error("No type supplied / type is not a valid type constraint");
+ }
+
$self->type_constraints->{$type->name} = $type;
}
shift;
my %args = @_;
- my $role = $args{for_class}
- or Moose->throw_error("Cannot call init_meta without specifying a for_class");
+ my $role = $args{for_class};
+
+ unless ($role) {
+ require Moose;
+ Moose->throw_error("Cannot call init_meta without specifying a for_class");
+ }
my $metaclass = $args{metaclass} || "Moose::Meta::Role";
my $meta;
if ($role->can('meta')) {
$meta = $role->meta();
- (blessed($meta) && $meta->isa('Moose::Meta::Role'))
- || Moose->throw_error("You already have a &meta function, but it does not return a Moose::Meta::Role");
+
+ unless ( blessed($meta) && $meta->isa('Moose::Meta::Role') ) {
+ require Moose;
+ Moose->throw_error("You already have a &meta function, but it does not return a Moose::Meta::Role");
+ }
}
else {
$meta = $metaclass->initialize($role);
sub apply_all_roles {
my $applicant = shift;
- Moose->throw_error("Must specify at least one role to apply to $applicant") unless @_;
+ unless (@_) {
+ require Moose;
+ Moose->throw_error("Must specify at least one role to apply to $applicant");
+ }
my $roles = Data::OptList::mkopt( [@_] );
Class::MOP::load_class( $role_spec->[0] );
}
- ( $_->[0]->can('meta') && $_->[0]->meta->isa('Moose::Meta::Role') )
- || Moose->throw_error("You can only consume roles, "
- . $_->[0]
- . " is not a Moose role")
- foreach @$roles;
+ foreach my $role (@$roles) {
+ unless ( $role->[0]->can('meta')
+ && $role->[0]->meta->isa('Moose::Meta::Role') ) {
+
+ require Moose;
+ Moose->throw_error( "You can only consume roles, "
+ . $role->[0]
+ . " is not a Moose role" );
+ }
+ }
if ( scalar @$roles == 1 ) {
my ( $role, $params ) = @{ $roles->[0] };