Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Diagnostic for that weird error we just got #1

Merged
merged 1 commit into from

2 participants

@mjdominus

If the target of the composed behavior is not a Moose class, the call
to 'apply_all_roles' will fail with a bizarre error message. This
cann occur if, for example, your "use Moose" declaration follows the
"use MooseX::ComposedBehavior" declaration in the target file.

Moose itself should diagnose this more clearly, but in the meantime we
add a diagnosis here.

@mjdominus mjdominus Better diagnostic message when target is not a Moose class
If the target of the composed behavior is not a Moose class, the call
to 'apply_all_roles' will fail with a bizarre error message.  This
cann occur if, for example, your "use Moose" declaration follows the
"use MooseX::ComposedBehavior" declaration in the target file.

Moose itself should diagnose this more clearly, but in the meantime we
add a diagnosis here.
6812641
@rjbs rjbs merged commit 6812641 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 7, 2011
  1. @mjdominus

    Better diagnostic message when target is not a Moose class

    mjdominus authored
    If the target of the composed behavior is not a Moose class, the call
    to 'apply_all_roles' will fail with a bizarre error message.  This
    cann occur if, for example, your "use Moose" declaration follows the
    "use MooseX::ComposedBehavior" declaration in the target file.
    
    Moose itself should diagnose this more clearly, but in the meantime we
    add a diagnosis here.
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 1 deletion.
  1. +8 −1 lib/MooseX/ComposedBehavior.pm
View
9 lib/MooseX/ComposedBehavior.pm
@@ -258,12 +258,19 @@ sub _build_composed_behavior {
INIT => sub {
my $target = $_[1]{into};
$_[0] = { target => $target };
+
+ # Applying roles to the target fails mysteriously if it is not (yet)
+ # something to which roles can be applied, for example if the "use
+ # Moose" decl appears after "use MooseX::ComposedBehavior" [MJD]
+ Moose::Util::find_meta($target)
+ or Carp::confess(__PACKAGE__ .
+ ": target package '$target' is not a Moose class");
Moose::Util::apply_all_roles($target, $role);
return 1;
},
},
});
-
+
$sub{import} = $import;
return \%sub;
Something went wrong with that request. Please try again.