CondBlock.pm 756B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package SugarTrail::Template::CondBlock;
  2. # condition block
  3. # init()
  4. # parse(string)
  5. # matches(data)
  6. use strict;
  7. use warnings;
  8. use Data::Dumper;
  9. sub init {
  10. my $class = shift;
  11. my $self = {};
  12. return bless $self, $class;
  13. }
  14. sub parse {
  15. my $self = shift;
  16. my $string = shift;
  17. my @parts = split ";", $string;
  18. foreach (@parts) {
  19. s/^\s+//;
  20. s/\s+$//;
  21. my ($n, $o, $v) = m/([a-zA-Z0-9_ ]+)([<>=~+\-*@]*)(.*)/;
  22. next unless $n;
  23. $n =~ s/\s+$//;
  24. $o =~ s/\s+$//;
  25. $o =~ s/^\s+//;
  26. $v =~ s/\s+$//;
  27. my @v = split m/\s*,\s*/, $v;
  28. push @{$self->{conds}}, { n => $n, o => $o, v => \@v };
  29. }
  30. }
  31. sub match {
  32. my $self = shift;
  33. my $args = shift;
  34. }
  35. 1;