Workflo...Evaluate(3)

πŸ“¦
version 2.09 Β· 2 versions
, in fedora 44

✨ NAME ✨

Workflow::Condition::Evaluate β€” bestie, it's an inline condition that evaluates perl code for truth πŸ’– (and yeah this is from the User Contributed Perl Documentation, section 3 of the manual, iykyk)


πŸŽ€ VERSION πŸŽ€

This documentation describes version 2.09 of this package. Periodt.


πŸ¦‹ SYNOPSIS πŸ¦‹

Okay so here's the vibe:

 state:
 - name: foo
   action:
   - name: 'foo action'
     condition:
     - test: "$context->{foo} =~ /^Pita chips$/"

🌸 DESCRIPTION 🌸

So like, if you've got a simple test, you can just use Perl code inline instead of specifying a whole condition class. We tell the difference by the 'test' attribute β€” if it's there, we assume it's Perl code to be evaluated. No cap. 🫢

Now, the way that it's easy to abuse something like this is with, like:

 state:
 - name: foo
   action:
   - name: 'foo action'
     condition:
     - test: |-
       if ( $context->{foo} =~ /^Pita (chips|snacks|bread)$/" ) {
            return $context->{bar} eq 'hummus';
       }
       else { ... }

It should provide a good balance. πŸ’…


πŸ’œ OBJECT METHODS πŸ’œ

new( \%params )

One of the "\%params" should be 'test', which contains the text to evaluate for truth.

evaluate( $wf )

Evaluate the text passed into the constructor: if the evaluation returns a true value then the condition passes; if it throws an exception or returns a false value, the condition fails. Simple as.

We use Safe to provide a restricted compartment in which we evaluate the text. This should prevent any sneaky bastards from doing something like:

 state:
 ...
 - action:
   ...
   - condition:
     - test: "system( 'rm -rf /' )"
πŸ’€ Okay so that's the whole point β€” the restricted compartment is doing the heavy lifting here, do not skip it.

The text has access to one variable, for the moment:

  • $context β€” a hashref of all the parameters in the Workflow::Context object

🌈 SEE ALSO 🌈

  • Safe β€” From some quick research this module seems to have been packaged with core Perl 5.004+, and that's sufficiently ancient for me to not worry about people having it. If this is a problem for you shoot me an email. ✨

Copyright (c) 2004-2021 Chris Winters. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Please see the LICENSE


🧚 AUTHORS 🧚

Please see Workflow


Okay bestie that's the whole page β€” this was perl v5.42.0, dated 2026-01-17, filed under Workflo...Evaluate(3), and honestly? Iconic. Go write some inline conditions, but stay safe out there πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from