diomedea has asked for the wisdom of the Perl Monks concerning the following question:

Greetings monks,

I am trying to use the cpan Workflow module but despite having read (and reread) the docs seem to be coming unstuck on what I think is a basic lack of my understanding of OO Perl, Im hoping some experienced monks might be able to point me in the right direction ....
just as a simple test example to upload a file I have a workflow xml:
<workflow type="uplfile" persister="Filesystem"> <time_zone>local</time_zone> <description>This is the Blast sequence alignment workflow.</desc +ription> <state name="INITIAL" autorun="yes"> <action name="upload file" resulting_state="uploaded" /> </state> <state name="uploaded" autorun="yes"> <action name="null" resulting_state="finished"> </action> </state> <state name="finished" /> </workflow>
and a corresponding action.xml
<actions> <type>uplfile</type> <action name="upload file" class="myapp::Upload_file"> </action> <action name="null" class="Workflow::Action::Null" /> </actions>
in the myapp subdirectory there is an Upload_file.pm which simply opens up and prints out a short text sequence:
package Upload_file; use strict; use Fcntl; use base qw( Workflow::Action ); use Workflow::Exception qw( workflow_error ); sub new { my $class = shift; my $self = {}; bless ($self, $class); return $self; } sub execute { my ( $self, $wf ) = @_; my $ifile = "/mypath/to/codelib/perl/lib/myapp/testseq.txt"; sysopen(IFILE, $ifile, O_RDONLY) or die "Can't open $ifile : $!"; my @file = <IFILE>; close IFILE; print "testseq is ", @file, "\n"; return 1; } 1;

when I try and execute this action from the calling script:
#! /bin/perl -w use strict; use Workflow::Factory qw( FACTORY ); use Fcntl; use File::Basename; Log::Log4perl::init('l4p.conf'); my $workflow_conf = 'wf_test.xml'; my $action_conf = 'action.xml'; my $pers = 'persister.xml'; FACTORY->add_config_from_file( workflow => $workflow_conf, action => $action_conf, persister => $pers, ); my $wf = FACTORY->fetch_workflow('uplfile', "PITGKDNR"); print "Workflow 1 ", $wf->id, " ", "currently at state ", $wf->state, "\n"; print "Available actions: ", $wf->get_current_actions, "\n"; $wf->execute_action('upload file');

the execute action fails:
Workflow 1 PITGKDNR currently at state INITIAL Available actions: upload file Can't locate object method "new" via package "myapp::Upload_file" at / +lib/x86_64/pkg/perl-5.8.8/lib/site_perl/5.8.8/Workflow/Factory.pm lin +e 546.

but there is a new method in the Upload_file package, and if I call
Upload_file->new()->execute();

instead I get the text from the file (but not via the workflow of course)...

Replies are listed 'Best First'.
Re: Workflow module problem
by Anonymous Monk on Jun 03, 2009 at 15:22 UTC
    splain
    Can't locate object method "new" via package "myapp::Upload_file" at /lib/x86_64/pkg/perl-5.8.8/lib/site_perl/5.8.8/Workflow/Factory.pm lin +e 546 (#1) (F) You called a method correctly, and it correctly indicated a packag +e functioning as a class, but that package doesn't define that particula +r method, nor does any of its base classes. See perlobj.
    There is no package myapp::Upload_file;, you only have package Upload_file; Module name must agree with filename. See Simple Module Tutorial.
      ok thanks, that does help, although if I add package myapp:Upload_file I get a Workflow module error:
      Can't use an undefined value as an ARRAY reference at /ebi/msd/sw/x86_ +64/pkg/perl-5.8.8/lib/site_perl/5.8.8/Workflow/Action.pm line 66.

      which relates to this function in Action.pm of Workflow:
      sub get_validators { my ($self) = @_; return @{ $self->{_validators} }; }


      think this is basically telling me that I have to have validators in the workflow not just a workflow.xml and action.xml - the cpan docs arent too clear on what is optional and this is my first outing into workflows ;+)

      ok nailed it, I had mistakenly put a constructor in the application class, now works