Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: handling tasks and customizing flow of tasks using perl

by vsespb (Chaplain)
on Sep 29, 2013 at 13:08 UTC ( #1056219=note: print w/replies, xml ) Need Help??

in reply to handling tasks and customizing flow of tasks using perl

Instead of XML, you can introduce simple text format:
task=B pretask=makeAServerdown posttask=checkBServer
Then you can parse it and call pretask/posttask as perl method:
use strict; use warnings; use Data::Dumper; sub makeAServerdown { print "AHA:", @_, "\n"; } my $line = 'task=B pretask=makeAServerdown posttask=checkBServer'; my $h = { map { my ($k,$v) = split /=/; $k=>$v } split (' ', $line) }; print Dumper $h; { no strict 'refs'; $h->{pretask}->($h->{task}); } __END__ $VAR1 = { 'pretask' => 'makeAServerdown', 'task' => 'B', 'posttask' => 'checkBServer' }; AHA:B

Replies are listed 'Best First'.
Re^2: handling tasks and customizing flow of tasks using perl
by asham (Novice) on Sep 29, 2013 at 14:48 UTC
    Hi vsespb, Thanks a lot for sharing your suggestions. I am not sure, if I understood the way you are integrating tasks and customizations but it seems following:
    1) $h (hash) so used in your file(should be standard file?). 2) the module should be then included in task side code where the $h o +f this module will be read.
    Advantage seems to be that xml parser overhead is not required. but then again xml/text have their own pros and cons.
    Some concerns: 1) are you suggesting reading this : "task=B pretask=makeAServerdown p +osttask=checkBServer" from some text file. or hardcoding in code? I a +m assuming text file for now. 2) The customizations suggested by you will work if only known action +is being called. But my use case is that user can customize with anyt +hing they like i.e. they can maybe add any code block they want etc. example of code block: (simple example here) for (int i=0;i<10;i++) { print('just a block for fun: ' . $i . "\n"); }
    Kindly look into this and please correct me as required.
      1) are you suggesting reading this : "task=B pretask=makeAServerdown posttask=checkBServer" from some text file.
      2) The customizations suggested by you will work if only known action is being called.

      If you need arbitrary code execution, write an API for programmers.

      I don't see any reason mixing API for programmers and for normal users, nor I don't see use of XML/other formats in API for programmers.

      Or, parhaps, I misunderstand the OP.
        Hi vsespb, thanks for the clarification.

        in my xml, my idea was that normal users will just change the flow if required. expert users will have additional feature to add pretasks/post tasks.

        Idea is to identify a solution which supports plug and play/customization and at the same time provides flexibility to the flow. perl/xml solution is just an idea, we can ignore it if we have better solutions available.

        Btw, updated question with a real life example.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056219]
[Discipulus]: dear brother karl has "Furthermore I consider that Donald Trump must be impeached as soon as possible" in his sig
[erix]: ah, thanks Discipulus
[1nickt]: erix perhaps you could kindly point out your technique to roho and everyone will be happy.
[Discipulus]: but i'm also animalist, so i' hirted by 1nickt's sig: The way forward always starts with a mammal test... grin..
[erix]: I might if I did remember. It's probably somewhere in the site docs
[uhClem]: I don't favor that sort of thing around here but the place for our politics is wherever we live.
[uhClem]: And besides, the objection to it was off-topic.
[Discipulus]: 1nickt hide signature is a positive action; i think is not a solution here

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2017-06-22 12:36 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (519 votes). Check out past polls.