Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Workflow CPAN distribution.

Report information
The Basics
Id: 62018
Status: resolved
Priority: 0/
Queue: Workflow

People
Owner: jonasbn [...] cpan.org
Requestors: luismiguelferreirasilva [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: feature request - specify "static" arguments to the actions
Date: Sat, 9 Oct 2010 12:54:42 -0600
To: bug-Workflow [...] rt.cpan.org
From: Luis Miguel Silva <luismiguelferreirasilva [...] gmail.com>
Dear Pel Workflow devs, I would like to start by thanking you all for the awesome job you did with the Perl Workflow module. I've been researching for a workflow engine i could use in my projects and your module is really sweet! I just recently started using it so i'm still getting to know all the details. But one of the things i noticed is that i could not find any documentation (or even figure out how to do it, even browsing through the code) is the ability to specify static arguments to the actions! I was really excited to find out how powerful the module already is as i could easily create loop and if conditions with it. But what i'm really needing right now is the ability to do something like this: <workflow> <type>myworkflow</type> <description>This is my workflow.</description> <persister>MainPersister</persister> <state name="INITIAL"> <description>this is the initial state</description> <action name="create file"> <resulting_state return="OK" state="created file" /> <resulting_state return="*" state="error_handler" /> </action> </state> <state name="error_handler" autorun="yes"> <action name="log_error" resulting_state="failed"> <condition test="defined $context->{error_message}" /> </action> <!-- even if we cant find anything to log, we still want to fail! --> <action name="null" resulting_state="failed"> <condition test="!defined $context->{error_message}" /> </action> </state> </workflow> And then have my log_error action configured like this: <actions> <action name="log_error" class="MyApp::Action::LogError"> <param name="log_message" value="An error occurred: $context->{error_message}"/> </action> </actions> Just so you better understand what i'm trying to do, i'm basically creating a bunch of reutilizable modules and trying to create a project that will allow people to either develop extra modules OR use the pre existing ones and not have to develop a single line of code! The objective is that people can fully customize their workflow logic, just by editing the xml flows (which, in my opinion, is the whole purpose of using a workflow engine ;o)). Another really cool feature would be the ability to run multiple actions when "autorun" is specified: <state name="verified file" autorun="yes"> <action name="always_gets_run" resulting_state="verified file" run_order="1"/> <action name="does_not_get_run" resulting_state="loop_example" run_order="2"/> </state> Right now, when autorun is activated, the flow will only run one if there is only one action inside OR multiple actions do not conflict with each other. It would be a HUGE enhancement to be able to specify a "run_order" so that individual states could have multiple actions! I obviously understand this is a community so...if we want something done, we should try and do it ourselves heheh ;o) But i thought i would send out an email to send all you guys my appreciation and try to understand if this already exists? (also because i really believe it would be really useful for other users and because i'm a novice perl coder and don't want to write something that will never make it to the official repo :oP). Thanks a lot! Luis
Subject: Re: [rt.cpan.org #62018] AutoReply: feature request - specify "static" arguments to the actions
Date: Sat, 9 Oct 2010 18:45:37 -0600
To: bug-Workflow [...] rt.cpan.org
From: Luis Miguel Silva <luismiguelferreirasilva [...] gmail.com>
Oh k, so i just found out how to pass static parameters to actions! :o)) It turns out you can ALSO use <param> tags inside <action> tags! :o)) Here it is (in case anybody else needs this in the future): <action name="log_error" class="MyApp::Action::LogError" > <field name="error_message" description="template error message" is_required="yes" /> <param name="message_format" value="here is what i saw: %s"/> <param name="something" value="else" /> <param name="else" value="something" /> </action> And your action can access it like this: [root@xcat workflow_tests]# cat MyApp/Action/LogError.pm package MyApp::Action::LogError; use strict; use base qw( Workflow::Action ); use Log::Log4perl qw( get_logger ); use Workflow::History; use Workflow::Exception qw( condition_error workflow_error); #use Workflow::Exception qw( workflow_error ); $MyApp::Action::LogError::VERSION = '1.00'; sub execute { my ( $self, $wf ) = @_; my $log = get_logger(); $log->debug( "Action '", $self->name, "' with class ", "'", ref( $self ), "' executing..." ); ####################### THE PARAMETERS ARE AVAILABLE INSIDE THE $self hash ($self->{'PARAMS'}) #print Data::Dumper->Dump([$self]); ####################### SO HERE IS AN EXAMPLE ON HOW TO ACCESS THE FIRST PARAMETER... #print "param key is: " . $self->{'PARAMS'}{'param'}[0]{'name'} . "\n"; #print "param value is: " . $self->{'PARAMS'}{'param'}[0]{'value'} . "\n"; ####################### OR COUNT HOW MANY PARAMETERS THERE ARE... #my $count = scalar (@{$self->{'PARAMS'}{'param'}}); #print "there are " . $count . " parameters!\n"; # OR CYCLE THROUGH THEM ALL UNTIL YOU FIND THE ONE YOU ARE LOOKING FOR ;o) my $message_format; foreach (@{$self->{'PARAMS'}{'param'}}) { my %tmp_hash = %{$_}; #print "\tname: " . $tmp_hash{'name'} . "\n"; #print "\tvalue: " . $tmp_hash{'value'} . "\n"; #print "\t######################\n"; if ($tmp_hash{'name'} eq 'message_format') { $message_format = $tmp_hash{'value'}; } } my $error_message = sprintf($message_format, $wf->context->param( 'error_message' )); } 1; [root@xcat workflow_tests]# Pardon my awful code but, like i mentioned in my previous email, i don't usually code in Perl :o) Thanks, Luis
Hi Luis, I understand from your second response you figured it out yourself? It is nice you use the RT system, but fell free to use the mailing list in the future, both for speedier feedback and wider communication. http://sourceforge.net/mail/?group_id=177533 You have provided us with material, which should go into a FAQ or similar - thanks for taking the time to write. Please let me/us know if there is anything else, jonasbn, current maintainer of Workflow