Git Product home page Git Product logo

between's Introduction

NAME
    Between - simple range objects for smart matching

SYNOPSIS
     use Between;
     use Math::Trig qw(pi);
 
     if ( pi ~~between(3,4) ) {
        say "This is to be expected.";
     }

DESCRIPTION
    This module is designed to make common range-testing constructions a
    little bit easier. Instead of this:

     if (18 <= $person->age and $person->age <= 70) {
        ...
     }

    You would write this:

     if ( $person->age ~~between(18,70) ) {
        ...
     }

    The latter is more readable, and in some cases (if the "age" method call
    were computationally expensive) more efficient.

  Functional Interface
    "between($start, $end)"
        This is a shortcut for the constructor (see the section below
        describing the object-oriented interface).

  Object-Oriented Interface
    "Between->new($start, $end)"
        Creates a new Between object, representing a range between $start
        and $end (inclusive).

        A third argument is allowed, a number interpreted as bit flags,
        which allows $start and $end to be treated exclusively instead of
        inclusively.

         $range = Between->new(0, 1, EXCLUSIVE_START);
         $range = Between->new(0, 1, EXCLUSIVE_START | EXCLUSIVE_END);

        A fourth parameter may be provided, indicating if numeric or string
        comparisons should be used. By default, the comparison type is
        guessed.

         $range = Between->new(0, 1, undef, '<=>');  # numeric
         $range = Between->new(0, 1, undef, 'cmp');  # string

    "start"
        This method returns the start of the range.

    "end"
        This method returns the end of the range.

    "start_is_exclusive"
        This method returns true iff the start of the range is exclusive.

    "end_is_exclusive"
        This method returns true iff the end of the range is exclusive.

    "type"
        The (possibly automatically detected) comparison type. Either 'cmp'
        or '<=>'.

    "to_string"
        A printable string representation for this range.

    "cmp"
        Equivalent to the Perl "cmp" operator.

          $range->cmp($value)

        will return 1 if $value is less than "$range->start"; return 0 if
        $value is within the range; and return -1 if <$value> is greater
        than "$range->end". It takes into account the inclusive/exclusive
        flags.

    "cmp_numeric"
        Like "cmp", but always does numeric comparison.

    "cmp_string"
        Like "cmp", but always does string comparison.

    "match"
        Returns a boolean opposite to "cmp". That is, the following returns
        true if and only if $value is within the range:

          $range->match($value)

  Constants
    *   EXCLUSIVE_START 0x01

    *   EXCLUSIVE_END 0x02

    *   CMP_NUMERIC '<=>'

    *   CMP_STRING 'cmp'

    *   CMP_AUTO "undef"

    Constants are not exported by default, but can be exported using the
    ':constants' or ':all' export tags.

     use Between qw(:constants);

  Overloading
    The Between module overloads the following operations:

    *   "~~" (smart match) via "match".

    *   "" (stringification) via "to_string".

    *   "cmp" (string comparison), "lt", "gt", "le", "ge", "eq", "ne" via
        "cmp_string".

    *   "<=>" (numeric comparison), "<", ">", "<=", ">=", "==", "!=" via
        "cmp_numeric".

  Export
    The following export tags are defined:

    *   ":standard" - exports the "between" function only.

    *   ":constants" - exports "EXCLUSIVE_START", "EXCLUSIVE_END",
        "CMP_NUMERIC", "CMP_STRING" and "CMP_AUTO".

    *   ":all" - combines ":standard" and ":constants".

    By default, the ":standard" tag is exported.

BUGS
    Please report any bugs to
    <http://rt.cpan.org/Dist/Display.html?Queue=Between>.

SEE ALSO
    Object::Range.

AUTHOR
    Toby Inkster <[email protected]>.

COPYRIGHT AND LICENCE
    This software is copyright (c) 2012 by Toby Inkster.

    This is free software; you can redistribute it and/or modify it under
    the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTIES
    THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
    WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
    MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

between's People

Contributors

tobyink avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.