root/trunk/plagger/lib/Plagger/Operator.pm

Revision 54 (checked in by miyagawa, 15 years ago)
  • Added update.fixup phase to do splicing across updates
  • Added Splice::Tag sample to aggregate entries based on specific tags
  • Added Plagger::Operator utility module (refs #23)
  • Added $feed->id stub (refs #16)
  • Added $entry->has_tag method
  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Operator;
2 use strict;
3
4 use List::Util qw(reduce);
5
6 our %Ops = (
7     AND  => [ sub { $_[0] && $_[1] } ],
8     OR   => [ sub { $_[0] || $_[1] } ],
9     XOR  => [ sub { $_[0] xor $_[1] } ],
10     NAND => [ sub { $_[0] && $_[1] }, 1 ],
11     NOT  => [ sub { $_[0] && $_[1] }, 1 ], # alias of NAND
12     NOR  => [ sub { $_[0] || $_[1] }, 1 ],
13 );
14
15 sub is_valid_op {
16     my($class, $op) = @_;
17     exists $Ops{$op};
18 }
19
20 sub call {
21     my($class, $op, @bool) = @_;
22
23     my $bool = reduce { $Ops{$op}->[0]->($a, $b) } @bool;
24     $bool = !$bool if $Ops{$op}->[1];
25     $bool;
26 }
27
28 1;
Note: See TracBrowser for help on using the browser.