[Moose-commits] r7979 - in MooseX-Params-Validate/trunk: .
lib/MooseX/Params t
isillitoe at code2.0beta.co.uk
isillitoe at code2.0beta.co.uk
Wed Dec 9 19:06:54 GMT 2009
Author: isillitoe
Date: 2009-12-09 11:06:54 -0800 (Wed, 09 Dec 2009)
New Revision: 7979
Added:
MooseX-Params-Validate/trunk/t/010.overloaded.t
Modified:
MooseX-Params-Validate/trunk/README
MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm
Log:
- Fix so that overloaded methods do not get called accidentally (causes problems when using these functions within overloaded methods)
- Tests for above
- Bumped version in README so it is consistent with the current dist (0.13)
Modified: MooseX-Params-Validate/trunk/README
===================================================================
--- MooseX-Params-Validate/trunk/README 2009-11-29 16:42:46 UTC (rev 7978)
+++ MooseX-Params-Validate/trunk/README 2009-12-09 19:06:54 UTC (rev 7979)
@@ -1,4 +1,4 @@
-MooseX::Params::Validate version 0.12
+MooseX::Params::Validate version 0.13
===========================
See the individual module documentation for more information
Modified: MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm
===================================================================
--- MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm 2009-11-29 16:42:46 UTC (rev 7978)
+++ MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm 2009-12-09 19:06:54 UTC (rev 7979)
@@ -60,7 +60,7 @@
called => _caller_name(),
);
- return ( ( $instance ? $instance : () ), %args );
+ return ( ( defined $instance ? $instance : () ), %args );
}
*validate = \&validated_hash;
@@ -108,7 +108,7 @@
);
return (
- ( $instance ? $instance : () ),
+ ( defined $instance ? $instance : () ),
@args{@ordered_spec}
);
}
Added: MooseX-Params-Validate/trunk/t/010.overloaded.t
===================================================================
--- MooseX-Params-Validate/trunk/t/010.overloaded.t (rev 0)
+++ MooseX-Params-Validate/trunk/t/010.overloaded.t 2009-12-09 19:06:54 UTC (rev 7979)
@@ -0,0 +1,36 @@
+
+package Foo;
+use Moose;
+use MooseX::Params::Validate;
+use overload (
+ qw{""} => 'to_string',
+);
+
+has 'id' => ( is => 'ro', isa => 'Str', default => '1.10.100' );
+
+sub to_string {
+ my ($self, %args) = validated_hash( \@_,
+ padded => { isa => 'Bool', optional => 1, default => 0 },
+ );
+
+ # 1.10.100 => 0001.0010.0100
+ my $id = $args{ padded }
+ ? join( '.', map { sprintf( "%04d", $_ ) } split( /\./, $self->id ) )
+ : $self->id;
+
+ return $id;
+}
+
+package main;
+use Test::More tests => 4;
+use strict;
+use warnings;
+
+isa_ok( my $foo = Foo->new(), 'Foo', 'new' );
+
+is( $foo->id, '1.10.100', 'id' );
+
+is( $foo->to_string, '1.10.100', 'to_string' );
+
+is( $foo->to_string( padded => 1 ), '0001.0010.0100', 'to_string( padded => 1 )' );
+
More information about the Moose-commits
mailing list