Number-Compare-0.03/00007551Ӏ-0000000000011636371656017577 5ustar richardcLONDON_domain_usersNumber-Compare-0.03/Changes00006441Ӏ-0000000110411636371542021060 0ustar richardcLONDON_domain_users0.03 21st September, 2011 Generate a new tarball on linux. Doing the C on OSX generated a tarball that upset dumb tars tar: Ignoring unknown extended header keyword `SCHILY.dev' tar: Ignoring unknown extended header keyword `SCHILY.ino' tar: Ignoring unknown extended header keyword `SCHILY.nlink' 0.02 12th September, 2011 - apply warning-related fix - https://rt.cpan.org/Public/Bug/Display.html?id=58466 0.01 23rd October, 2002 - Refactored the code away from File::Find::Rule - Initial release Number-Compare-0.03/lib/00007551Ӏ-0000000000011636371656020345 5ustar richardcLONDON_domain_usersNumber-Compare-0.03/lib/Number/00007551Ӏ-0000000000011636371656021575 5ustar richardcLONDON_domain_usersNumber-Compare-0.03/lib/Number/Compare.pm00006441Ӏ-0000000453611636371553023525 0ustar richardcLONDON_domain_userspackage Number::Compare; use strict; use Carp qw(croak); use vars qw/$VERSION/; $VERSION = '0.03'; 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, C), megabytes (C, C), or gigabytes (C, C). Those suffixed with an C 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 =head1 COPYRIGHT Copyright (C) 2002,2011 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 Number-Compare-0.03/Makefile.PL00006441Ӏ-0000000026211633345134021536 0ustar richardcLONDON_domain_usersuse ExtUtils::MakeMaker; WriteMakefile( NAME => 'Number::Compare', VERSION_FROM => 'lib/Number/Compare.pm', PREREQ_PM => { 'Test::More' => 0, }, ); Number-Compare-0.03/MANIFEST00006441Ӏ-0000000024311636371656020727 0ustar richardcLONDON_domain_usersChanges MANIFEST MANIFEST.SKIP Makefile.PL t/Number-Compare.t lib/Number/Compare.pm META.yml Module meta-data (added by MakeMaker) Number-Compare-0.03/MANIFEST.SKIP00006441Ӏ-0000000005311633343436021463 0ustar richardcLONDON_domain_users\.svn \.cvsignore blib pm_to_blib Makefile Number-Compare-0.03/META.yml00006441Ӏ-0000000075211636371656021054 0ustar richardcLONDON_domain_users--- #YAML:1.0 name: Number-Compare version: 0.03 abstract: ~ author: [] license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: Test::More: 0 no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.57_05 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 Number-Compare-0.03/t/00007551Ӏ-0000000000011636371656020042 5ustar richardcLONDON_domain_usersNumber-Compare-0.03/t/Number-Compare.t00006441Ӏ-0000000244611633343436023041 0ustar richardcLONDON_domain_users#!perl -w # $Id$ 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" );