HashRef. Keeps an inventory of what plugins are loaded and what the actual
module name is to avoid multiple loading.
-=head2 __plugin_subclass
+=head2 _plugin_subclass
Object. This holds the subclass of our pluggable object in the form of an
anonymous L<Moose::Meta::Class> instance. All roles are actually applied to
this instance instead of the original class instance in order to not lose
the original object name as roles are applied. The anonymous class will be
-automatically generated upon first use.
+automatically generated.
=cut
has _plugin_loaded => (is => 'rw', required => 1, isa => 'HashRef',
default => sub{ {} });
-has __plugin_subclass => ( is => 'rw', required => 0, isa => 'Object', );
+has _plugin_subclass => ( is => 'rw', required => 0, isa => 'Object', );
#--------#---------#---------#---------#---------#---------#---------#---------#
There's nothing stopping you from using these, but if you are using them
you are probably doing something wrong.
-=head2 _plugin_subclass
+=head2 BUILD
-Creates, if needed and returns the anonymous instance of the consuming objects
-subclass to which roles will be applied to.
+Extend BUILD to create a suitable C<anon_subclass>.
=cut
-sub _plugin_subclass{
- my $self = shift;
- my $anon_class = $self->__plugin_subclass;
-
- #initialize if we havnt been initialized already.
- unless(ref $anon_class && $self->meta->is_anon_class){
-
- #create an anon class that inherits from $self that plugins can be
- #applied to safely and store it within the $self instance.
- $anon_class = Moose::Meta::Class->
- create_anon_class(superclasses => [$self->meta->name]);
- $self->__plugin_subclass( $anon_class );
-
- #rebless $self as the anon class which now inherits from ourselves
- #this allows the anon class to override methods in the consuming
- #class while keeping a stable name and set of superclasses
- bless $self => $anon_class->name
- unless $self->meta->name eq $anon_class->name;
- }
+around BUILD => sub {
+ my ($super,$self) = @_;
- return $anon_class;
-}
+ #create an anon class that inherits from $self that plugins can be
+ #applied to safely and store it within the $self instance.
+ my $anon_class = Moose::Meta::Class->
+ create_anon_class(superclasses => [$self->meta->name]);
+ $self->_plugin_subclass( $anon_class );
+
+ #rebless $self as the anon class which now inherits from ourselves
+ #this allows the anon class to override methods in the consuming
+ #class while keeping a stable name and set of superclasses
+ bless $self => $anon_class->name
+ unless $self->meta->name eq $anon_class->name;
+
+ $super->($self);
+};
=head2 _role_from_plugin $plugin
$plugin =~ /^\+(.*)/ ? $1 : join '::', $name, $self->_plugin_ns, $plugin;
}
+#sub original_class_name{
+# my $self = shift;
+#
+# $self->meta->is_anon_class ?
+# ($self->meta->superclasses)[0] : $self->blessed;
+#}
+
=head2 _load_and_apply_role $role
Require C<$role> if it is not already loaded and apply it to