use Scalar::Util 'blessed';
use Class::MOP 0.60;
-our $VERSION = '0.73';
+our $VERSION = '0.74';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
find_meta
does_role
search_class_by_role
+ ensure_all_roles
apply_all_roles
get_all_init_args
get_all_attribute_values
return;
}
+# this can possibly behave in unexpected ways because the roles being composed
+# before being applied could differ from call to call; I'm not sure if or how
+# to document this possible quirk.
+sub ensure_all_roles {
+ my $applicant = shift;
+ _apply_all_roles($applicant, sub { !does_role($applicant, $_) }, @_);
+}
+
sub apply_all_roles {
my $applicant = shift;
+ _apply_all_roles($applicant, sub { 1 }, @_);
+}
+
+sub _apply_all_roles {
+ my $applicant = shift;
+ my $role_filter = shift;
unless (@_) {
require Moose;
}
}
+ @$roles = grep { local $_ = $_->[0]; $role_filter->() } @$roles;
+
+ return unless @$roles;
+
my $meta = ( blessed $applicant ? $applicant : find_meta($applicant) );
if ( scalar @$roles == 1 ) {
followed by an optional hash reference of options (C<exclude> and
C<alias>).
+=item B<ensure_all_roles($applicant, @roles)>
+
+This function is similar to L</apply_all_roles>, but only applies roles that
+C<$applicant> does not already consume.
+
=item B<get_all_attribute_values($meta, $instance)>
Returns a hash reference containing all of the C<$instance>'s