YAML::Logic

Simple boolean logic in YAML
Download

YAML::Logic Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Michael Schilli
  • Publisher web site:
  • http://search.cpan.org/~mschilli/

YAML::Logic Tags


YAML::Logic Description

Simple boolean logic in YAML YAML::Logic is a Perl module that allows users to define simple boolean logic in a configuration file, without permitting them to run arbitrary code.While Perl code can be controlled with the Safe module, Safe can't prevent the user from defining infinite loops, exhausting all available memory or crashing the interpreter by exploiting well-known perl bugs. YAML::Logic isn't perfect in this regard either, but it makes it reasonably hard to define harmful code.The syntax for the boolean logic within a YAML file was inspired by John Siracusa's Rose::DB::Object::QueryBuilder module, which provides data structures to define logic that is then transformed into SQL. YAML::Logic takes the data structure instead and transforms it into Perl code.For example, the data structure to check whether a variable $var is equal to a value "foo", looks like this: It's a reference to an array containing both the value of the variable and the value to compare it with. In YAML, this looks like rule: - $var - fooand this is exactly the syntax that YAML::Logic accepts. Note that after parsing the YAML configuration above, you need to pass only the array ref inside the rule entry to YAML::Logic's evaluate() method: $logic->evaluate( $yaml_data->{rule}, ...Passing the entire YAML data would cause an error with YAML::Logic, as it expects to receive an array ref.SYNOPSIS use YAML::Syck qw(Load); use YAML::Logic; my $logic = YAML::Logic->new(); ### Tests defined somewhere in a YAML file ... my $data = Load(q{ # is $var equal to "foo"? rule: - $var - foo }); ### Tests performed in application code: if( $logic->evaluate( $data->{rule}, { var => "foo" }) ) { print "True! "; } Requirements: · Perl


YAML::Logic Related Software