From 39cd8c52774be37226a3015c7c13d5b42a68d95e Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 7 Nov 2005 12:10:45 +0000 Subject: aggiunta struttura base pipeline, e test, re #2 git-svn-id: svn://luxion/repos/WebCoso/trunk@23 fcb26f47-9200-0410-b104-b98ab5b095f3 --- lib/WebCoso/Pipeline/Base.pm | 37 +++++++++++++++++++++++++++++++++++++ lib/WebCoso/Step.pm | 18 ++++++++++++++++++ lib/WebCoso/X.pm | 11 +++++++++++ 3 files changed, 66 insertions(+) create mode 100644 lib/WebCoso/Pipeline/Base.pm create mode 100644 lib/WebCoso/Step.pm (limited to 'lib') diff --git a/lib/WebCoso/Pipeline/Base.pm b/lib/WebCoso/Pipeline/Base.pm new file mode 100644 index 0000000..7018fc0 --- /dev/null +++ b/lib/WebCoso/Pipeline/Base.pm @@ -0,0 +1,37 @@ +package WebCoso::Pipeline::Base; +use strict; +use warnings; +use WebCoso::X; +use WebCoso::Step; +use base 'Class::Data::Inheritable'; + +__PACKAGE__->mk_classdata('_steps'); + +sub set_steps { + my ($class,@steps)=@_; + + my @full_steps=map { + my $full_step_name="WebCoso::Step::$_"; + if (! WebCoso::Step->is_step($full_step_name)) { + WebCoso::X::NoSuchStep->throw( + pipeline => $class, + step => $_, + ); + } + $full_step_name; + } @steps; + + $class->_steps([@full_steps]); +} + +sub process { + my ($class, $resource)=@_; + + for my $step (@{$class->_steps()}) { + $resource = $step->process($resource); + } + + return 1; +} + +1; diff --git a/lib/WebCoso/Step.pm b/lib/WebCoso/Step.pm new file mode 100644 index 0000000..71a4f07 --- /dev/null +++ b/lib/WebCoso/Step.pm @@ -0,0 +1,18 @@ +package WebCoso::Step; +use strict; +use warnings; +use Module::Pluggable::Fast + name => '_steps', + search => [ 'WebCoso::Step' ], + require => 1; + +my @steps=_steps(); +my %steps; +@steps{@steps}=(); + +sub is_step { + my ($class,$step_name)=@_; + return exists $steps{$step_name}; +} + +1; diff --git a/lib/WebCoso/X.pm b/lib/WebCoso/X.pm index 1894a28..57acd58 100644 --- a/lib/WebCoso/X.pm +++ b/lib/WebCoso/X.pm @@ -37,6 +37,11 @@ use Exception::Class fields => [ 'resource' ], description => 'è stata richiesta una risorsa ignota', }, + 'WebCoso::X::NoSuchStep' => { + isa => 'WebCoso::X::Base', + fields => [ 'pipeline', 'step' ], + description => 'una pipeline vuole usare uno step ignoto', + }, ); WebCoso::X::Base->Trace(1); @@ -71,4 +76,10 @@ sub WebCoso::X::NoSuchResource::full_message { return 'Risorsa ignota: ' . $self->resource(); } +sub WebCoso::X::NoSuchStep::full_message { + my ($self)=@_; + + return 'La pipeline ' . $self->pipeline() . ' vuole usare lo step ' . $self->step() . ' che è ignoto'; +} + 1; -- cgit v1.2.3