Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.6 / 3....
  • Linux Kernel 3.0.82 LTS...
  • KDE Software Compilatio...
  • PulseAudio 4.0
  • Wireshark 1.10.0
  • NetworkManager 0.9.8.2
  • LibreOffice 3.6.6 / 4.0...
  • SystemRescueCd 3.7.0
  • Linux Kernel 3.10 RC6
  • Ubuntu Tweak 0.8.5
  • Home > Linux > Programming > Libraries

    Class::Comparable 0.02

    Download button

    No screenshots available
    Downloads: 374  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Stevan Little | More programs
    Perl Artistic License / FREE
    September 28th, 2007, 07:05 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    Class::Comparable 0.02 description

    Class::Comparable is a base class for comparable objects.



    SYNOPSIS

    # an example subclass

    package Currency::USD;

    use base 'Class::Comparable';

    sub new {
    my $class = shift;
    bless { value => shift }, $class;
    }

    sub value { (shift)->{value} }

    sub compare {
    my ($left, $right) = @_;
    # if we are comparing against another
    # currency object, then compare values
    if (ref($right) && $right->isa('Currency::USD')) {
    return $left->value $right->value;
    }
    # otherwise assume we are comparing
    # against a numeric value of some kind
    else {
    return $left->value $right;
    }
    }

    # an example usage of Class::Comparable object

    my $buck_fifty = Currency::USD->new(1.50);
    my $dollar_n_half = Currenty::USD->new(1.50);

    ($buck_fifty == $dollar_n_half) # these are equal
    (1.75 > $buck_fifty) # 1.75 is more than a buck fifty

    my $two_bits = Currency::USD->new(0.25);

    ($two_bits < $dollar_n_half) # 2 bits is less than a dollar and a half
    ($two_bits == 0.25) # two bits is equal to 25 cents

    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    comparable objects | Perl class | Perl module | Perl | class | compare

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM