package Set::Range; require Exporter; use constant DATE_RANGE => 1; use constant NUM_RANGE => 2; use constant TIME_RANGE => 3; use constant EU_DATE_RANGE => 4; @ISA = qw(Exporter); @EXPORT = qw(DATE_RANGE EU_DATE_RANGE NUM_RANGE TIME_RANGE); sub new { my $self = shift; my $range = shift; return bless $range, $self; } sub getSet { my ($self, $var, $type) = @_; $type = NUM_RANGE unless $type; if (($type == DATE_RANGE) || ($type == EU_DATE_RANGE)) { $var = _timify($var, $type); } my $state = 0; foreach $state (keys %$self) { my ($u, $l) = ($self->{$state}->{upper}, $self->{$state}->{lower}); if (($type == DATE_RANGE) || ($type == EU_DATE_RANGE)) { $upper= _timify($u, $type); $lower= _timify($l, $type); } my ($uinc, $linc, $result); if ($self->{$state}->{upper_inclusive}) { $uinc = '>='; } else { $uinc = '>' } if ($self->{$state}->{lower_inclusive}) { $linc = '>='; } else { $linc = '>' } $result = eval "$state if (($u $uinc $var) && ($var $linc $l))"; return $result if $result; } return 0; } sub _timify { my ($u, $type) = @_; require Date::Calc; if ($type == EU_DATE_RANGE) { $u = Date::Calc::Date_to_Days(Date::Calc::Decode_Date_EU($u)); } else { $u = Date::Calc::Date_to_Days(Date::Calc::Decode_Date_US($u)); } return $u; }

In reply to Set::Range - conditional testing on sets by $code or die

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.