r47184 - in /branches/upstream/libnumber-range-perl: ./ current/ current/Changes current/MANIFEST current/META.yml current/Makefile.PL current/README current/lib/ current/lib/Number/ current/lib/Number/Range.pm current/t/ current/t/Number-Range.t

midget-guest at users.alioth.debian.org midget-guest at users.alioth.debian.org
Sat Nov 14 21:21:48 UTC 2009


Author: midget-guest
Date: Sat Nov 14 21:21:43 2009
New Revision: 47184

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=47184
Log:
[svn-inject] Installing original source of libnumber-range-perl

Added:
    branches/upstream/libnumber-range-perl/
    branches/upstream/libnumber-range-perl/current/
    branches/upstream/libnumber-range-perl/current/Changes   (with props)
    branches/upstream/libnumber-range-perl/current/MANIFEST
    branches/upstream/libnumber-range-perl/current/META.yml
    branches/upstream/libnumber-range-perl/current/Makefile.PL   (with props)
    branches/upstream/libnumber-range-perl/current/README   (with props)
    branches/upstream/libnumber-range-perl/current/lib/
    branches/upstream/libnumber-range-perl/current/lib/Number/
    branches/upstream/libnumber-range-perl/current/lib/Number/Range.pm   (with props)
    branches/upstream/libnumber-range-perl/current/t/
    branches/upstream/libnumber-range-perl/current/t/Number-Range.t   (with props)

Added: branches/upstream/libnumber-range-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnumber-range-perl/current/Changes?rev=47184&op=file
==============================================================================
--- branches/upstream/libnumber-range-perl/current/Changes (added)
+++ branches/upstream/libnumber-range-perl/current/Changes Sat Nov 14 21:21:43 2009
@@ -1,0 +1,33 @@
+Revision history for Perl extension Number::Range.
+
+0.01  Fri Mar 19 12:02:36 2004
+	- original version; created by h2xs 1.23 with options
+		-AX -n Number::Range
+
+0.02  Sat Mar 20 2004
+	- Added the ability to add and delete ranges from existing
+		range.
+
+0.03  Mon Mar 22, 2004
+	- Allowed inrange() to take a list of tests, and return a
+	  list of true/false if in array context, or single true
+	  if all are true, or a false if one of them is false.
+
+0.04  Tue Mar 23, 2004
+	- Created range() to output either a list of all numbers
+		in the range, or to output a range format, depending
+		on list context.
+
+0.05  Mon May 17, 2004
+	- Cleaned up POD and documentation.
+	- Created the size() method to return number of elements
+		in the range.
+
+0.06 Wed July 21, 2004
+	- Cleaned up POD
+	- Added a SEE ALSO for Number::Tollerant 
+
+0.06 Tue April 29, 2008
+	- Fix #15478, if a range is 1,3,4,5,6 don't return 1..1,3..6
+	  instead, return 1,3..6
+	  Thanks to noodles

Propchange: branches/upstream/libnumber-range-perl/current/Changes
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libnumber-range-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnumber-range-perl/current/MANIFEST?rev=47184&op=file
==============================================================================
--- branches/upstream/libnumber-range-perl/current/MANIFEST (added)
+++ branches/upstream/libnumber-range-perl/current/MANIFEST Sat Nov 14 21:21:43 2009
@@ -1,0 +1,7 @@
+Changes
+Makefile.PL
+MANIFEST
+README
+t/Number-Range.t
+lib/Number/Range.pm
+META.yml                                 Module meta-data (added by MakeMaker)

Added: branches/upstream/libnumber-range-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnumber-range-perl/current/META.yml?rev=47184&op=file
==============================================================================
--- branches/upstream/libnumber-range-perl/current/META.yml (added)
+++ branches/upstream/libnumber-range-perl/current/META.yml Sat Nov 14 21:21:43 2009
@@ -1,0 +1,10 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         Number-Range
+version:      0.07
+version_from: lib/Number/Range.pm
+installdirs:  site
+requires:
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.30

Added: branches/upstream/libnumber-range-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnumber-range-perl/current/Makefile.PL?rev=47184&op=file
==============================================================================
--- branches/upstream/libnumber-range-perl/current/Makefile.PL (added)
+++ branches/upstream/libnumber-range-perl/current/Makefile.PL Sat Nov 14 21:21:43 2009
@@ -1,0 +1,9 @@
+use ExtUtils::MakeMaker;
+WriteMakefile(
+    NAME              => 'Number::Range',
+    VERSION_FROM      => 'lib/Number/Range.pm', 
+    PREREQ_PM         => {},
+    ($] >= 5.005 ?
+      (ABSTRACT_FROM  => 'lib/Number/Range.pm',
+       AUTHOR         => 'Larry Shatzer, Jr. <larrysh at cpan.org>') : ()),
+);

Propchange: branches/upstream/libnumber-range-perl/current/Makefile.PL
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libnumber-range-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnumber-range-perl/current/README?rev=47184&op=file
==============================================================================
--- branches/upstream/libnumber-range-perl/current/README (added)
+++ branches/upstream/libnumber-range-perl/current/README Sat Nov 14 21:21:43 2009
@@ -1,0 +1,26 @@
+Number-Range version 0.06
+=========================
+
+Number::Range is an object-oriented interface to test if a number exists in a
+given range, and to be able to manipulate the range.
+
+INSTALLATION
+
+To install this module type the following:
+
+   perl Makefile.PL
+   make
+   make test
+   make install
+
+DEPENDENCIES
+
+Nothing that is outside of the core Perl modules.
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2004 by Larry Shatzer, Jr.
+
+This library is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
+

Propchange: branches/upstream/libnumber-range-perl/current/README
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libnumber-range-perl/current/lib/Number/Range.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnumber-range-perl/current/lib/Number/Range.pm?rev=47184&op=file
==============================================================================
--- branches/upstream/libnumber-range-perl/current/lib/Number/Range.pm (added)
+++ branches/upstream/libnumber-range-perl/current/lib/Number/Range.pm Sat Nov 14 21:21:43 2009
@@ -1,0 +1,275 @@
+package Number::Range;
+
+use strict;
+use warnings;
+use warnings::register;
+use Carp;
+
+require Exporter;
+
+our @ISA = qw(Exporter);
+
+
+our $VERSION = '0.07';
+
+sub new {
+  my $this = shift;
+  my $class = ref($this) || $this;
+  my $self = {};
+  bless $self, $class;
+  $self->initialize("add", @_);
+  return $self;
+}
+
+sub initialize {
+  my $self = shift;
+  my $type = shift;
+  my $rangesep = qr/(?:\.\.)/;
+  my $sectsep  = qr/(?:\s|,)/;
+  my $validation = qr/(?:
+       [^0-9,. -]|        # These are the only allowed characters (Numbers and "separators")
+       $rangesep$sectsep| # We don't want a range separator followed by section separator
+       $sectsep$rangesep| # We don't want a section separator followed by range separator
+       \d-\d|             # We don't want 10-10 since - is for negative numbers
+       ^$sectsep|         # We don't want a section separator at the start
+       ^$rangesep|        # We don't want a range separator at the start
+       $sectsep$|         # We don't want a section separator at the end
+       $rangesep$         # We don't want a range separator at the end
+       )/x;
+  foreach my $item (@_) {
+    croak "$item contains invalid data" if ($item =~ m/$validation/g);
+    foreach my $section (split(/$sectsep/, $item)) {
+      if ($section =~ m/$rangesep/) {
+        my ($start, $end) = split(/$rangesep/, $section, 2);
+        if ($start > $end) {
+          carp "$start is > $end" if (warnings::enabled());
+          ($start, $end) = ($end, $start);
+        }
+        if ($start == $end) {
+          carp "$start:$end is pointless" if (warnings::enabled());
+          if ($type eq "add") {
+            $self->_addnumbers($start);
+          }
+          elsif ($type eq "del") {
+            $self->_delnumbers($start);
+          }
+          else {
+            die "Neither 'add' nor 'del' was passed initialize()";
+          }
+        }
+        else {
+          if ($type eq "add") {
+            $self->_addnumbers($start .. $end);
+          }
+          elsif ($type eq "del") {
+            $self->_delnumbers($start .. $end);
+          }
+          else {
+            die "Neither 'add' nor 'del' was passed initialize()";
+          }
+        }
+      }
+      else {
+        if ($type eq "add") {
+           $self->_addnumbers($section);
+         }
+         elsif ($type eq "del") {
+          $self->_delnumbers($section);
+         }
+         else {
+          die "Neither 'add' nor 'del' was passed initialize()";
+        }
+      }
+    }
+  }
+}
+
+sub _addnumbers {
+  my $self = shift;
+  foreach my $number (@_) {
+    if (warnings::enabled()) {
+      carp "$number already in range" if $self->inrange($number);
+    }
+    $self->{_rangehash}{$number} = 1;
+  }
+}
+
+sub _delnumbers {
+  my $self = shift;
+  foreach my $number (@_) {
+    if (warnings::enabled()) {
+      carp "$number not in range or already removed" if (!$self->inrange($number));
+    }
+    delete $self->{_rangehash}{$number};
+  }
+}
+
+sub inrange {
+  my $self   = shift;
+  if (scalar(@_) == 1) {
+    return (exists($self->{_rangehash}{$_[0]})) ? 1 : 0;
+  } else {
+    if (wantarray) {
+      my @returncodes;
+      foreach my $test (@_) {
+        push(@returncodes, ($self->inrange($test)) ? 1 : 0);
+      }
+      return @returncodes;
+    } else {
+      foreach my $test (@_) {
+        if (!$self->inrange($test)) {
+          return 0;
+        }
+        return 1;
+      }
+    }
+  }
+}
+
+sub addrange {
+  my $self = shift;
+  $self->initialize("add", @_);
+}
+
+sub delrange {
+  my $self = shift;
+  $self->initialize("del", @_);
+}
+
+sub range {
+  my $self = shift;
+  if (wantarray) {
+    my @range = keys(%{$self->{_rangehash}});
+    my @sorted = sort {$a <=> $b} @range;
+    return @sorted;
+  }
+  else {
+    my @range    = $self->range;
+    my $previous = shift @range;
+    my $format   = "$previous";
+    foreach my $current (@range) {
+      if ($current == ($previous + 1)) {
+        $format =~ s/\.\.$previous$//;
+        $format .= "..$current"; 
+      }
+      else {
+        $format .= ",$current";
+      }
+      $previous = $current;
+    }
+    return $format;
+  }
+}
+
+sub size {
+  my $self = shift;
+  my @temp = $self->range;
+  return scalar(@temp);
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Number::Range - Perl extension defining ranges of numbers and testing if a
+number is found in the range. You can also add and delete from this range.
+
+=head1 SYNOPSIS
+
+  use Number::Range;
+
+  my $range = Number::Range->new("-10..10,12,100..120");
+  if ($range->inrange("13")) {
+    print "In range\n";
+  } else {
+    print "Not in range\n";
+  }
+  $range->addrange("200..300");
+  $range->delrange("250..255");
+  my $format = $range->range;
+  # $format will be '-10..10,12,100..120,200..249,256..300'
+
+=head1 DESCRIPTION
+
+Number::Range will take a description of a range, and then allow you to test on
+if a number falls within the range. You can also add and delete from the range.
+
+=head2 RANGE FORMAT
+
+The format used for range is pretty straight forward. To separate sections of
+ranges it uses a C<,> or whitespace. To create the range, it uses C<..> to do
+this, much like Perl's own binary C<..> range operator in list context.
+
+=head2 METHODS
+
+=over
+
+=item new
+
+  $range = Number::Range->new("10..20","25..30");
+
+Creates the range object. It will accept any number of ranges as its 
+input.
+
+=item addrange
+
+  $range->addrange("22");
+
+This will also take any number of ranges as input and add them to the 
+existing range.
+
+=item delrange
+
+  $range->delrange("10");
+
+This will also take any number of ranges as input and delete them from the
+existing range.
+
+=item inrange
+
+  $range->inrange("26"); my @results = $range->inrange("27","200");
+
+This will take one or more numbers and check if each of them exists in the
+range. If passed a list, and in array context, it will return a list of C<0>'s
+or C<1>'s, depending if that one was true or false in the list position. If in
+scalar context, it will return a single C<1> if all are true, or a single C<0>
+if one of them failed.
+
+=item range
+
+  $format = $range->range; @numbers = $range->range;
+
+Depending on context this will return either an array of all the numbers found
+in the range, for list context. For scalar context it will return a range
+string.
+
+=item size
+
+  $size = $range->size;
+
+This will return the total number of entries in the range.
+
+=back
+
+=head2 EXPORT
+
+None by default.
+
+=head1 SEE ALSO
+
+L<Number::Tolerant>, L<Tie::RangeHash>, and L<Array::IntSpan> for similar
+modules.
+
+=head1 AUTHOR
+
+Larry Shatzer, Jr., E<lt>larrysh at cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2004-8 by Larry Shatzer, Jr.
+
+This library is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut

Propchange: branches/upstream/libnumber-range-perl/current/lib/Number/Range.pm
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libnumber-range-perl/current/t/Number-Range.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnumber-range-perl/current/t/Number-Range.t?rev=47184&op=file
==============================================================================
--- branches/upstream/libnumber-range-perl/current/t/Number-Range.t (added)
+++ branches/upstream/libnumber-range-perl/current/t/Number-Range.t Sat Nov 14 21:21:43 2009
@@ -1,0 +1,38 @@
+use Test::More tests => 25;
+BEGIN { use_ok('Number::Range') };
+
+ok($range = Number::Range->new("10..100"));
+ok($range->inrange(10)   == 1);
+ok($range->inrange(1000) == 0);
+$range = Number::Range->new("10..50,60..100");
+ok($range->inrange(10) == 1);
+ok($range->inrange(55) == 0);
+ok($range->inrange(75) == 1);
+$range = Number::Range->new("10..100","150..200");
+ok($range->inrange(10)  == 1);
+ok($range->inrange(125) == 0);
+ok($range->inrange(155) == 1);
+$range = Number::Range->new("-10..10");
+ok($range->inrange(10)  == 1);
+ok($range->inrange(-10) == 1);
+ok($range->inrange(0)   == 1);
+$range->addrange("20..30");
+ok($range->inrange(25) == 1);
+ok($range->inrange(10) == 1);
+ok($range->inrange(15) == 0);
+$range->delrange("-10..0");
+ok($range->inrange(-10) == 0);
+ok($range->inrange(10)  == 1);
+ok($range->inrange(25) == 1);
+ok($range->inrange(10,25));
+ at test = $range->inrange(10,25,1000);
+ at rc   = qw/1 1 0/;
+is_deeply(\@rc, \@test);
+$range = Number::Range->new("1..100,150..200");
+$rangeformat = $range->range;
+cmp_ok("1..100,150..200", 'eq', $rangeformat);
+ok($range->size == 151);
+$range = Number::Range->new("1,3,4,5,6");
+ok($range->range eq "1,3..6");
+$range = Number::Range->new("1,2,3,4,5,6");
+ok($range->range eq "1..6");

Propchange: branches/upstream/libnumber-range-perl/current/t/Number-Range.t
------------------------------------------------------------------------------
    svn:executable = 




More information about the Pkg-perl-cvs-commits mailing list