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