From: Guillermo Roditi Date: Mon, 2 Jun 2008 20:40:49 +0000 (+0000) Subject: bye bye extensions X-Git-Tag: 0.0008~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7579722e7bd4a7f31d2f94527399021deaaf7734;p=gitmo%2FMooseX-Object-Pluggable.git bye bye extensions --- diff --git a/Changes b/Changes index a6c8a7a..1dab29c 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,8 @@ Revision history for MooseX-Object-Pluggable +0.0008 + Cleanup Aattribute declarations + Eliminate extension mechanisms + 0.0007 Jan 22, 2008 Fix for Moose 0.34 @@ -7,21 +11,26 @@ Revision history for MooseX-Object-Pluggable Added load_plugins Test while classes are immutable for good measure. Remove use strict and use warnings. Moose does it for us. + 0.0005 Apr 13, 2007 Goodbye Class::Inspector, hello Module::Object::Pluggable More Tests App namespaces functionality. Test for app namespaces functionality + 0.0004 Jan 23, 2007 PODFixes + 0.0003 Jan 19, 2007 Forget anon classes, go back to applying to $self goodbye __anon_subclass and _anon_subclass hello _original_class_name Props to mst for pointing out the error of my ways A couple more minor tests + 0.0002 Jan 16, 2007 Forgot Class::Inspector dep on Makefile + 0.0001 Jan 16, 2007 Initial Release! diff --git a/lib/MooseX/Object/Pluggable.pm b/lib/MooseX/Object/Pluggable.pm index ceaacb2..f02f28e 100644 --- a/lib/MooseX/Object/Pluggable.pm +++ b/lib/MooseX/Object/Pluggable.pm @@ -5,7 +5,7 @@ use Moose::Role; use Class::MOP; use Module::Pluggable::Object; -our $VERSION = '0.0007'; +our $VERSION = '0.0008'; =head1 NAME @@ -69,11 +69,6 @@ C<$self-Eblessed> and C will no longer return the name of your ob they will instead return the name of the anonymous class created at runtime. See C<_original_class_name>. -=head1 Notice regarding extensions. - -Because I have been able to identify a real-world use case for the extension mechanism -I have decided to deprecate it and remove it in the next major release. - =head1 Usage For a simple example see the tests included in this distribution. @@ -84,23 +79,6 @@ For a simple example see the tests included in this distribution. String. The prefix to use for plugin names provided. MyApp::Plugin is sensible. -=head2 _plugin_ext - -Boolean. Indicates whether we should attempt to load plugin extensions. -Defaults to true; - -=head2 _plugin_ext_ns - -B If you use -this, please email me, but I am fairly sure that nobody uses this at -all and it's just adding bloat and making things kind of ugly. - -String. The namespace plugin extensions have. Defaults to 'ExtensionFor'. - -This means that is _plugin_ns is "MyApp::Plugin" and _plugin_ext_ns is -"ExtensionFor" loading plugin "Bar" would search for extensions in -"MyApp::Plugin::Bar::ExtensionFor::*". - =head2 _plugin_app_ns ArrayRef, Accessor automatically dereferences into array on a read call. @@ -120,25 +98,43 @@ available plugins. #--------#---------#---------#---------#---------#---------#---------#---------# -has _plugin_ns => (is => 'rw', required => 1, isa => 'Str', - default => 'Plugin'); -has _plugin_ext => (is => 'rw', required => 1, isa => 'Bool', - default => 1); -has _plugin_ext_ns => (is => 'rw', required => 1, isa => 'Str', - default => 'ExtensionFor'); -has _plugin_loaded => (is => 'rw', required => 1, isa => 'HashRef', - default => sub{ {} }); -has _plugin_app_ns => (is => 'rw', required => 1, isa => 'ArrayRef', lazy => 1, - auto_deref => 1, - default => sub{ shift->_build_plugin_app_ns }, - trigger => sub{ $_[0]->_clear_plugin_locator - if $_[0]->_has_plugin_locator; }, - ); -has _plugin_locator => (is => 'rw', required => 1, lazy => 1, - isa => 'Module::Pluggable::Object', - clearer => '_clear_plugin_locator', - predicate => '_has_plugin_locator', - default => sub{ shift->_build_plugin_locator }); +has _plugin_ns => + ( + is => 'rw', + required => 1, + isa => 'Str', + default => sub{ 'Plugin' }, + ); + +has _plugin_loaded => + ( + is => 'rw', + required => 1, + isa => 'HashRef', + default => sub{ {} } + ); + +has _plugin_app_ns => + ( + is => 'rw', + required => 1, + isa => 'ArrayRef', + lazy => 1, + auto_deref => 1, + builder => '_build_plugin_app_ns', + trigger => sub{ $_[0]->_clear_plugin_locator if $_[0]->_has_plugin_locator; }, + ); + +has _plugin_locator => + ( + is => 'rw', + required => 1, + lazy => 1, + isa => 'Module::Pluggable::Object', + clearer => '_clear_plugin_locator', + predicate => '_has_plugin_locator', + builder => '_build_plugin_locator' + ); #--------#---------#---------#---------#---------#---------#---------#---------# @@ -148,8 +144,7 @@ has _plugin_locator => (is => 'rw', required => 1, lazy => 1, =head2 load_plugin $plugin -Load the apropriate role for C<$plugin> as well as any extensions it provides -if extensions are enabled. +Load the apropriate role for C<$plugin>. =cut @@ -158,18 +153,11 @@ sub load_plugins { die("You must provide a plugin name") unless @plugins; my $loaded = $self->_plugin_loaded; - my @load = grep { not exists $loaded->{$_} } @plugins; - my @roles = map { $self->_role_from_plugin($_) } @load; if ( $self->_load_and_apply_role(@roles) ) { @{ $loaded }{@load} = @roles; - - if ( $self->_plugin_ext ) { - $self->load_plugin_ext($_) for @load; - } - return 1; } else { return; @@ -182,45 +170,6 @@ sub load_plugin { $self->load_plugins(@_); } - -=head2 load_plugin_ext - -B If you use -this, please email me, but I am fairly sure that nobody uses this at -all and it's just adding bloat and making things kind of ugly. - -Will load any extensions for a particular plugin. This should be called -automatically by C so you don't need to worry about it. -It basically attempts to load any extension that exists for a plugin -that is already loaded. The only reason for using this is if you want to -keep _plugin_ext as false and only load extensions manually, which I don't -recommend. - -=cut - -sub load_plugin_ext{ - my ($self, $plugin) = @_; - die("You must provide a plugin name") unless $plugin; - my $role = $self->_plugin_loaded->{$plugin}; - - # $p for plugin, $r for role - while( my($p,$r) = each %{ $self->_plugin_loaded }){ - - my $ext = join "::", $role, $self->_plugin_ext_ns, $p; - if( $plugin =~ /^\+(.*)/ ){ - eval{ $self->_load_and_apply_role( $ext ) }; - } else{ - $self->_load_and_apply_role( $ext ) if - grep{ /^${ext}$/ } $self->_plugin_locator->plugins; - } - - #go back to prev loaded modules and load extensions for current module? - #my $ext2 = join "::", $r, $self->_plugin_ext_ns, $plugin; - #$self->_load_and_apply_role( $ext2 ) - # if Class::Inspector->installed($ext2); - } -} - =head2 _original_class_name Because of the way roles apply C<$self-Eblessed> and C will @@ -239,8 +188,7 @@ sub _original_class_name{ There's nothing stopping you from using these, but if you are using them for anything thats not really complicated you are probably doing -something wrong. Some of these may be inlined in the future if performance -becomes an issue (which I doubt). +something wrong. =head2 _role_from_plugin $plugin