[Moose-commits] r7960 - in MooseX-Params-Validate/trunk: .
lib/MooseX/Params t
autarch at code2.0beta.co.uk
autarch at code2.0beta.co.uk
Tue Jul 7 20:43:08 GMT 2009
Author: autarch
Date: 2009-07-07 13:43:07 -0700 (Tue, 07 Jul 2009)
New Revision: 7960
Added:
MooseX-Params-Validate/trunk/t/009_wrapped.t
Modified:
MooseX-Params-Validate/trunk/Makefile.PL
MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm
Log:
Use Devel::Caller to get a truly unique id (the refaddr of the calling
sub) for caching the validation spec.
Modified: MooseX-Params-Validate/trunk/Makefile.PL
===================================================================
--- MooseX-Params-Validate/trunk/Makefile.PL 2009-07-07 18:31:53 UTC (rev 7959)
+++ MooseX-Params-Validate/trunk/Makefile.PL 2009-07-07 20:43:07 UTC (rev 7960)
@@ -7,6 +7,7 @@
requires 'Carp' => '0';
+requires 'Devel::Caller' => '0';
requires 'Moose' => '0.58';
requires 'Params::Validate' => '0.88';
requires 'Scalar::Util' => '0';
Modified: MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm
===================================================================
--- MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm 2009-07-07 18:31:53 UTC (rev 7959)
+++ MooseX-Params-Validate/trunk/lib/MooseX/Params/Validate.pm 2009-07-07 20:43:07 UTC (rev 7960)
@@ -4,7 +4,8 @@
use warnings;
use Carp 'confess';
-use Scalar::Util 'blessed';
+use Devel::Caller 'caller_cv';
+use Scalar::Util 'blessed', 'refaddr';
use Moose::Util::TypeConstraints qw( find_type_constraint class_type role_type );
use Params::Validate ();
@@ -163,7 +164,7 @@
return delete $spec->{MX_PARAMS_VALIDATE_CACHE_KEY};
}
else {
- return _caller_name(1);
+ return refaddr( caller_cv(2) );
}
}
Added: MooseX-Params-Validate/trunk/t/009_wrapped.t
===================================================================
--- MooseX-Params-Validate/trunk/t/009_wrapped.t (rev 0)
+++ MooseX-Params-Validate/trunk/t/009_wrapped.t 2009-07-07 20:43:07 UTC (rev 7960)
@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+use Test::Exception;
+
+{
+ package Foo;
+ use Moose;
+ use MooseX::Params::Validate;
+
+ sub foo {
+ my $self = shift;
+ my %params = validated_hash(
+ \@_,
+ foo => { isa => 'Str' },
+ );
+ return $params{foo};
+ }
+
+ around 'foo' => sub {
+ my $orig = shift;
+ my $self = shift;
+ my %p = @_;
+
+ my @args = ( bar => delete $p{bar} );
+
+ my %params = validated_hash(
+ \@args,
+ bar => { isa => 'Str' },
+ );
+
+ $params{bar}, $self->$orig(%p);
+ };
+
+ around 'foo' => sub {
+ my $orig = shift;
+ my $self = shift;
+ my %p = @_;
+
+ my @args = ( quux => delete $p{quux} );
+
+ my %params = validated_hash(
+ \@args,
+ quux => { isa => 'Str' },
+ );
+
+ $params{quux}, $self->$orig(%p);
+ };
+}
+
+{
+ my $foo = Foo->new;
+
+ is_deeply( [ $foo->foo( foo => 1, bar => 2, quux => 3 ) ],
+ [ 3, 2, 1 ],
+ 'multiple around wrappers can safely be cached' );
+
+ is_deeply( [ $foo->foo( foo => 1, bar => 2, quux => 3 ) ],
+ [ 3, 2, 1 ],
+ 'multiple around wrappers can safely be cached (2nd time)' );
+}
+
Property changes on: MooseX-Params-Validate/trunk/t/009_wrapped.t
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Rev
Name: svn:eol-style
+ native
More information about the Moose-commits
mailing list