17 if ($] >= 5.009_005) {
19 $impl = \&mro::get_linear_isa;
22 local $SIG{__DIE__} = 'DEFAULT';
23 eval { require MRO::Compat; 1 };
26 $impl = \&mro::get_linear_isa;
28 # VVVVV CODE TAKEN FROM MRO::COMPAT VVVVV
29 my $code; # this recurses so it isn't pretty
33 my $classname = shift;
35 my @lin = ($classname);
37 foreach my $parent (@{"$classname\::ISA"}) {
38 my $plin = $code->($parent);
40 next if exists $stored{$_};
47 # ^^^^^ CODE TAKEN FROM MRO::COMPAT ^^^^^
53 *{ __PACKAGE__ . '::get_linear_isa'} = $impl;
56 # taken from Class/MOP.pm
60 sub resolve_metaclass_alias {
61 my ( $type, $metaclass_name, %options ) = @_;
63 my $cache_key = $type;
64 return $cache{$cache_key}{$metaclass_name}
65 if $cache{$cache_key}{$metaclass_name};
67 my $possible_full_name =
74 load_first_existing_class( $possible_full_name,
77 return $cache{$cache_key}{$metaclass_name} =
78 $loaded_class->can('register_implementation')
79 ? $loaded_class->register_implementation
84 # taken from Class/MOP.pm
85 sub _is_valid_class_name {
88 return 0 if ref($class);
89 return 0 unless defined($class);
90 return 0 unless length($class);
92 return 1 if $class =~ /^\w+(?:::\w+)*$/;
97 # taken from Class/MOP.pm
98 sub load_first_existing_class {
102 foreach my $class (@classes) {
103 unless ( _is_valid_class_name($class) ) {
104 my $display = defined($class) ? $class : 'undef';
105 confess "Invalid class name ($display)";
111 for my $class (@classes) {
112 my $e = _try_load_one_class($class);
115 $exceptions{$class} = $e;
122 return $found if $found;
127 sprintf( "Could not load class (%s) because : %s",
128 $_, $exceptions{$_} )
133 # taken from Class/MOP.pm
134 sub _try_load_one_class {
137 return if Mouse::is_class_loaded($class);
139 my $file = $class . '.pm';
144 eval { require($file) };
149 sub apply_all_roles {
150 my $meta = Mouse::Meta::Class->initialize(shift);
154 # Basis of Data::OptList
155 my $max = scalar(@_);
156 for (my $i = 0; $i < $max ; $i++) {
157 if ($i + 1 < $max && ref($_[$i + 1])) {
158 push @roles, [ $_[$i++] => $_[$i] ];
160 push @roles, [ $_[$i] => {} ];
164 foreach my $role_spec (@roles) {
165 Mouse::load_class( $role_spec->[0] );
168 ( $_->[0]->can('meta') && $_->[0]->meta->isa('Mouse::Meta::Role') )
169 || croak("You can only consume roles, "
171 . " is not a Moose role")
174 if ( scalar @roles == 1 ) {
175 my ( $role, $params ) = @{ $roles[0] };
176 $role->meta->apply( $meta, ( defined $params ? %$params : () ) );
179 Mouse::Meta::Role->combine_apply($meta, @roles);
190 Mouse::Util - features, with or without their dependencies
192 =head1 IMPLEMENTATIONS FOR
194 =head2 L<MRO::Compat>
196 =head3 get_linear_isa