r3789 - in /packages/libnumber-compare-perl: ./ branches/
branches/upstream/
branches/upstream/current/ branches/upstream/current/t/ tags/
gregoa-guest at users.alioth.debian.org
gregoa-guest at users.alioth.debian.org
Thu Sep 14 22:35:13 UTC 2006
Author: gregoa-guest
Date: Thu Sep 14 22:35:12 2006
New Revision: 3789
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=3789
Log:
[svn-inject] Installing original source of libnumber-compare-perl
Added:
packages/libnumber-compare-perl/
packages/libnumber-compare-perl/branches/
packages/libnumber-compare-perl/branches/upstream/
packages/libnumber-compare-perl/branches/upstream/current/
packages/libnumber-compare-perl/branches/upstream/current/Changes
packages/libnumber-compare-perl/branches/upstream/current/Compare.pm
packages/libnumber-compare-perl/branches/upstream/current/MANIFEST
packages/libnumber-compare-perl/branches/upstream/current/MANIFEST.SKIP
packages/libnumber-compare-perl/branches/upstream/current/Makefile.PL
packages/libnumber-compare-perl/branches/upstream/current/t/
packages/libnumber-compare-perl/branches/upstream/current/t/Number-Compare.t
packages/libnumber-compare-perl/tags/
Added: packages/libnumber-compare-perl/branches/upstream/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnumber-compare-perl/branches/upstream/current/Changes?rev=3789&op=file
==============================================================================
--- packages/libnumber-compare-perl/branches/upstream/current/Changes (added)
+++ packages/libnumber-compare-perl/branches/upstream/current/Changes Thu Sep 14 22:35:12 2006
@@ -1,0 +1,3 @@
+0.01 23rd October, 2002
+ - Refactored the code away from File::Find::Rule
+ - Initial release
Added: packages/libnumber-compare-perl/branches/upstream/current/Compare.pm
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnumber-compare-perl/branches/upstream/current/Compare.pm?rev=3789&op=file
==============================================================================
--- packages/libnumber-compare-perl/branches/upstream/current/Compare.pm (added)
+++ packages/libnumber-compare-perl/branches/upstream/current/Compare.pm Thu Sep 14 22:35:12 2006
@@ -1,0 +1,100 @@
+# $Id: Compare.pm 846 2002-10-25 15:46:01Z richardc $
+package Number::Compare;
+use strict;
+use Carp qw(croak);
+use vars qw/$VERSION/;
+$VERSION = '0.01';
+
+sub new {
+ my $referent = shift;
+ my $class = ref $referent || $referent;
+ my $expr = $class->parse_to_perl( shift );
+
+ bless eval "sub { \$_[0] $expr }", $class;
+}
+
+sub parse_to_perl {
+ shift;
+ my $test = shift;
+
+ $test =~ m{^
+ ([<>]=?)? # comparison
+ (.*?) # value
+ ([kmg]i?)? # magnitude
+ $}ix
+ or croak "don't understand '$test' as a test";
+
+ my $comparison = $1 || '==';
+ my $target = $2;
+ my $magnitude = $3;
+ $target *= 1000 if lc $magnitude eq 'k';
+ $target *= 1024 if lc $magnitude eq 'ki';
+ $target *= 1000000 if lc $magnitude eq 'm';
+ $target *= 1024*1024 if lc $magnitude eq 'mi';
+ $target *= 1000000000 if lc $magnitude eq 'g';
+ $target *= 1024*1024*1024 if lc $magnitude eq 'gi';
+
+ return "$comparison $target";
+}
+
+sub test { $_[0]->( $_[1] ) }
+
+1;
+
+__END__
+
+=head1 NAME
+
+Number::Compare - numeric comparisons
+
+=head1 SYNOPSIS
+
+ Number::Compare->new(">1Ki")->test(1025); # is 1025 > 1024
+
+ my $c = Number::Compare->new(">1M");
+ $c->(1_200_000); # slightly terser invocation
+
+=head1 DESCRIPTION
+
+Number::Compare compiles a simple comparison to an anonymous
+subroutine, which you can call with a value to be tested again.
+
+Now this would be very pointless, if Number::Compare didn't understand
+magnitudes.
+
+The target value may use magnitudes of kilobytes (C<k>, C<ki>),
+megabytes (C<m>, C<mi>), or gigabytes (C<g>, C<gi>). Those suffixed
+with an C<i> use the appropriate 2**n version in accordance with the
+IEC standard: http://physics.nist.gov/cuu/Units/binary.html
+
+=head1 METHODS
+
+=head2 ->new( $test )
+
+Returns a new object that compares the specified test.
+
+=head2 ->test( $value )
+
+A longhanded version of $compare->( $value ). Predates blessed
+subroutine reference implementation.
+
+=head2 ->parse_to_perl( $test )
+
+Returns a perl code fragment equivalent to the test.
+
+=head1 AUTHOR
+
+Richard Clamp <richardc at unixbeard.net>
+
+=head1 COPYRIGHT
+
+Copyright (C) 2002 Richard Clamp. All Rights Reserved.
+
+This module is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+http://physics.nist.gov/cuu/Units/binary.html
+
+=cut
Added: packages/libnumber-compare-perl/branches/upstream/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnumber-compare-perl/branches/upstream/current/MANIFEST?rev=3789&op=file
==============================================================================
--- packages/libnumber-compare-perl/branches/upstream/current/MANIFEST (added)
+++ packages/libnumber-compare-perl/branches/upstream/current/MANIFEST Thu Sep 14 22:35:12 2006
@@ -1,0 +1,6 @@
+Changes
+Compare.pm
+MANIFEST
+MANIFEST.SKIP
+Makefile.PL
+t/Number-Compare.t
Added: packages/libnumber-compare-perl/branches/upstream/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnumber-compare-perl/branches/upstream/current/MANIFEST.SKIP?rev=3789&op=file
==============================================================================
--- packages/libnumber-compare-perl/branches/upstream/current/MANIFEST.SKIP (added)
+++ packages/libnumber-compare-perl/branches/upstream/current/MANIFEST.SKIP Thu Sep 14 22:35:12 2006
@@ -1,0 +1,5 @@
+\.svn
+\.cvsignore
+blib
+pm_to_blib
+Makefile
Added: packages/libnumber-compare-perl/branches/upstream/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnumber-compare-perl/branches/upstream/current/Makefile.PL?rev=3789&op=file
==============================================================================
--- packages/libnumber-compare-perl/branches/upstream/current/Makefile.PL (added)
+++ packages/libnumber-compare-perl/branches/upstream/current/Makefile.PL Thu Sep 14 22:35:12 2006
@@ -1,0 +1,13 @@
+use ExtUtils::MakeMaker;
+
+my $module = 'Compare.pm';
+WriteMakefile(NAME => 'Number::Compare',
+ VERSION_FROM => $module,
+ PREREQ_PM => { 'Test::More' => 0 });
+
+sub MY::postamble {
+ return <<EOF
+README: $module
+\tpod2text $module > README
+EOF
+}
Added: packages/libnumber-compare-perl/branches/upstream/current/t/Number-Compare.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libnumber-compare-perl/branches/upstream/current/t/Number-Compare.t?rev=3789&op=file
==============================================================================
--- packages/libnumber-compare-perl/branches/upstream/current/t/Number-Compare.t (added)
+++ packages/libnumber-compare-perl/branches/upstream/current/t/Number-Compare.t Thu Sep 14 22:35:12 2006
@@ -1,0 +1,50 @@
+#!perl -w
+# $Id: Number-Compare.t 846 2002-10-25 15:46:01Z richardc $
+use strict;
+use Test::More tests => 24;
+
+BEGIN { use_ok("Number::Compare") };
+
+my $c = Number::Compare->new('>20');
+ok( $c->test(21), ">20" );
+ok( !$c->test(20) );
+ok( !$c->test(19) );
+
+$c = Number::Compare->new('<20');
+ok( !$c->test(21), "<20" );
+ok( !$c->test(20) );
+ok( $c->test(19) );
+
+$c = Number::Compare->new('>=20');
+ok( $c->test(21), ">=20" );
+ok( $c->test(20) );
+ok( !$c->test(19) );
+
+$c = Number::Compare->new('<=20');
+ok( !$c->test(21), "<=20" );
+ok( $c->test(20) );
+ok( $c->test(19) );
+
+$c = Number::Compare->new('20');
+ok( !$c->test(21), "== 20" );
+ok( $c->test(20) );
+ok( !$c->test(19) );
+
+# well that's all the comparisons done, we'll not repeat that for each
+# of the magnitudes though
+
+ok( Number::Compare->new("2K")->test( 2_000), "K" );
+ok( Number::Compare->new("2M")->test( 2_000_000), "M" );
+ok( Number::Compare->new("2G")->test(2_000_000_000), "G" );
+
+ok( Number::Compare->new("2Ki")->test( 2_048), "Ki" );
+ok( Number::Compare->new("2Mi")->test( 2_097_152), "Mi" );
+ok( Number::Compare->new("2Gi")->test(2_147_483_648), "Gi" );
+
+# okay, how about if we become a blessed coderef
+
+ok( Number::Compare->new("1Ki")->(1024), "directly call the coderef" );
+
+# expose parse_to_perl
+
+is( Number::Compare->parse_to_perl(">1Ki"), '> 1024', "->parse_to_perl" );
More information about the Pkg-perl-cvs-commits
mailing list