From: Matt S Trout Date: Sat, 20 Jul 2013 17:43:26 +0000 (+0000) Subject: add plugins filtering plugins and implement RemovePlugin PagePlugin X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e2e7175f11789605d89be76f039855c604f92501;p=scpubgit%2FApp-SCS.git add plugins filtering plugins and implement RemovePlugin PagePlugin --- diff --git a/lib/App/SCS/Page.pm b/lib/App/SCS/Page.pm index 8cc33d9..355f129 100644 --- a/lib/App/SCS/Page.pm +++ b/lib/App/SCS/Page.pm @@ -45,9 +45,7 @@ sub with_plugin_config { return $self->with(plugins => pond_write_datum(\@new)); } -has _page_plugins => (is => 'lazy'); - -sub _build__page_plugins { +has _raw_page_plugins => (is => 'lazy', builder => sub { my ($self) = @_; my $plugin_config = $self->plugin_config; my ($plugin_map, $defaults) = @{$self->_page_set->plugin_config} @@ -58,11 +56,18 @@ sub _build__page_plugins { my $info = $plugin_map->{$name}; push @plugins, use_module($info->{class})->new( - ($info->{config}||sub{})->(), %$config, page => $self + ($info->{config}||sub{})->(), %$config, page => $self, + plugin_map => $plugin_map, # some things will need this ); } return \@plugins; -} +}); + +has _page_plugins => (is => 'lazy', builder => sub { + my ($self) = @_; + my $raw = $self->_raw_page_plugins; + reduce { $b->filter_plugins($a) } $raw, @$raw; +}); sub published_at { $_[0]->created diff --git a/lib/App/SCS/Plugin/Core.pm b/lib/App/SCS/Plugin/Core.pm index dba9001..7d9dfc6 100644 --- a/lib/App/SCS/Plugin/Core.pm +++ b/lib/App/SCS/Plugin/Core.pm @@ -32,6 +32,7 @@ sub _build_includes { sub page_plugins { my ($self) = @_; PageList => 'App::SCS::Plugin::Core::PagePlugin::PageList', + RemovePlugin => 'App::SCS::Plugin::Core::PagePlugin::RemovePlugin', Template => { class => 'App::SCS::Plugin::Core::PagePlugin::Template', config => sub { templates => $self->templates }, diff --git a/lib/App/SCS/Plugin/Core/PagePlugin/RemovePlugin.pm b/lib/App/SCS/Plugin/Core/PagePlugin/RemovePlugin.pm new file mode 100644 index 0000000..6348623 --- /dev/null +++ b/lib/App/SCS/Plugin/Core/PagePlugin/RemovePlugin.pm @@ -0,0 +1,21 @@ +package App::SCS::Plugin::Core::PagePlugin::RemovePlugin; + +use Moo; + +with 'App::SCS::Role::PagePlugin'; + +has name => (is => 'ro', required => 1); + +has plugin_map => (is => 'ro', required => 1); + +has class => (is => 'lazy', builder => sub { + my ($self) = @_; + $self->plugin_map->{$self->name}{class} +}); + +sub filter_plugins { + my ($self, $plugins) = @_; + [ grep !$_->isa($self->class), @$plugins ]; +} + +1; diff --git a/lib/App/SCS/Role/PagePlugin.pm b/lib/App/SCS/Role/PagePlugin.pm index ceee4cb..bfb1fbf 100644 --- a/lib/App/SCS/Role/PagePlugin.pm +++ b/lib/App/SCS/Role/PagePlugin.pm @@ -6,6 +6,8 @@ has 'page' => (is => 'ro', weak_ref => 1, required => 1); sub extra_pages { () } +sub filter_plugins { $_[1] } + sub filter_html_zoom { $_[1] } sub filter_content_zoom { $_[1] }