1Workflow::Condition::EvUasleuratCeo(n3t)ributed Perl DocWuomreknftlaotwi:o:nCondition::Evaluate(3)
2
3
4
6 Workflow::Condition::Evaluate - Inline condition that evaluates perl
7 code for truth
8
10 <state name="foo">
11 <action name="foo action">
12 <condition test="$context->{foo} =~ /^Pita chips$/" />
13
15 If you've got a simple test you can use Perl code inline instead of
16 specifying a condition class. We differentiate by the 'test' attribute
17 -- if it's present we assume it's Perl code to be evaluated.
18
19 While it's easy to abuse something like this with:
20
21 <condition>
22 <test><![CDATA[
23 if ( $context->{foo} =~ /^Pita (chips⎪snacks⎪bread)$/" ) {
24 return $context->{bar} eq 'hummus';
25 }
26 else { ... }
27 ]]>
28 </test>
29 </condition>
30
31 It should provide a good balance.
32
34 new( \%params )
35
36 One of the "\%params" should be 'test', which contains the text to
37 evaluate for truth.
38
39 evaluate( $wf )
40
41 Evaluate the text passed into the constructor: if the evaluation
42 returns a true value then the condition passes; if it throws an excep‐
43 tion or returns a false value, the condition fails.
44
45 We use Safe to provide a restricted compartment in which we evaluate
46 the text. This should prevent any sneaky bastards from doing something
47 like:
48
49 <state...>
50 <action...>
51 <condition test="system( 'rm -rf /' )" />
52
53 The text has access to one variable, for the moment:
54
55 $context
56 A hashref of all the parameters in the Workflow::Context object
57
59 Safe - From some quick research this module seems to have been packaged
60 with core Perl 5.004+, and that's sufficiently ancient for me to not
61 worry about people having it. If this is a problem for you shoot me an
62 email.
63
65 Copyright (c) 2004 Chris Winters. All rights reserved.
66
67 This library is free software; you can redistribute it and/or modify it
68 under the same terms as Perl itself.
69
71 Chris Winters <chris@cwinters.com>
72
73
74
75perl v5.8.8 2007-04-25 Workflow::Condition::Evaluate(3)