Class-Declare
view release on metacpan or search on metacpan
Replacement for B<UNIVERSAL::VERSION()>, that falls back to B<REVISION()>
to report the CVS revision number as the version number if the package
variable C<$VERSION> is not defined. If I<required> is given, then
B<VERSION()> will die if the I<required> version is not less than or equal
to the current package version (or revision, if B<VERSION()> falls back to
B<REVISION()>). B<VERSION()> will die if I<required> is not a valid version
string.
=cut
sub VERSION(;$)
{
my $self = __PACKAGE__->class( shift );
# extract the package version (if it exists)
# - fallback to the REVISION if there's no version
my $version = $self->SUPER::VERSION;
$version = $self->REVISION if ( ! defined $version );
$version = version->parse( $version ) if ( defined $version );
# have we been given a required version?
1;
# return to main for the tests
package main;
# create a test instance
my $class = 'Test::Hash::One';
my $object = $class->new;
# define an is_num() comparitor
sub is_num($)
{
# certain strings can cause the lines after this one to throw a
# warning, so let's try to catch it out
return 0 if ( $_[ 0 ] =~ /\W/o );
my $value = ( eval $_[ 0 ] ) || $_[ 0 ];
return ( ( $value & ~$value ) eq '0' );
} # is_num()
# define hash comparison routines
# - not a recursive comparison; just to the first-level values
sub cmp_hash($$)
{
my $a = shift;
my $b = shift;
# if both $a and $b are undefined, then they are considered the same
( $a && $b ) or return ( ! defined $a && ! defined $b );
# if $a and $b refer to the same hash then they are the same
( $a == $b ) and return 1;
( run in 0.799 second using v1.01-cache-2.11-cpan-65fba6d93b7 )