Permalink
Browse files

Added requester attribute of Params::Callback.

  • Loading branch information...
1 parent 509b312 commit 754dfcd9ad53761420d5f7643f689909a58c0c85 @theory committed May 26, 2006
Showing with 72 additions and 39 deletions.
  1. +3 −0 Changes
  2. +5 −5 META.yml
  3. +3 −2 Makefile.PL
  4. +43 −30 lib/Params/Callback.pm
  5. +18 −2 t/06object_request.t
View
@@ -1,6 +1,9 @@
Revision history for Perl extension Params::CallbackRequest.
1.15
+ - Added the 'requester' attribute to Params::Callback. This can be
+ specified by passing the 'requester' paremter to request(), and can be
+ anything.
1.14 2006-03-02T20:07:28
- Removed an unnecessary eval block around the loading of Class::ISA
View
@@ -1,6 +1,6 @@
---
name: Params-CallbackRequest
-version: 1.14
+version: 1.15
author:
- 'David Wheeler <david@kineticode.com>'
abstract: Functional and object-oriented callback architecture
@@ -20,14 +20,14 @@ recommends:
provides:
Params::Callback:
file: lib/Params/Callback.pm
- version: 1.14
+ version: 1.15
Params::CallbackRequest:
file: lib/Params/CallbackRequest.pm
- version: 1.14
+ version: 1.15
Params::CallbackRequest::Exceptions:
file: lib/Params/CallbackRequest/Exceptions.pm
- version: 1.14
-generated_by: Module::Build version 0.2707
+ version: 1.15
+generated_by: Module::Build version 0.2801
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.2.html
version: 1.2
View
@@ -18,8 +18,9 @@
# Save this 'cause CPAN will chdir all over the place.
my $cwd = Cwd::cwd();
- CPAN::Shell->install('Module::Build::Compat')
- or die " *** Cannot install without Module::Build. Exiting ...\n";
+ CPAN::Shell->install('Module::Build::Compat');
+ CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate
+ or die "Couldn't install Module::Build, giving up.\n";
chdir $cwd or die "Cannot chdir() back to $cwd: $!";
}
@@ -42,6 +42,7 @@ BEGIN {
priority
cb_key
pkg_key
+ requester
trigger_key
value )) {
no strict 'refs';
@@ -50,50 +51,53 @@ BEGIN {
*class_key = \&pkg_key;
}
-my %valid_params =
- ( cb_request =>
- { isa => 'Params::CallbackRequest',
- },
+my %valid_params = (
+ cb_request => { isa => 'Params::CallbackRequest' },
- params =>
- { type => Params::Validate::HASHREF,
+ params => {
+ type => Params::Validate::HASHREF,
},
- apache_req =>
- { isa => $ap_req_class,
- optional => 1,
+ apache_req => {
+ isa => $ap_req_class,
+ optional => 1,
},
- priority =>
- { type => Params::Validate::SCALAR,
- callbacks => $is_num,
- optional => 1,
- desc => 'Priority'
+ priority => {
+ type => Params::Validate::SCALAR,
+ callbacks => $is_num,
+ optional => 1,
+ desc => 'Priority'
},
- cb_key =>
- { type => Params::Validate::SCALAR,
- optional => 1,
- desc => 'Callback key'
+ cb_key => {
+ type => Params::Validate::SCALAR,
+ optional => 1,
+ desc => 'Callback key'
},
- pkg_key =>
- { type => Params::Validate::SCALAR,
- optional => 1,
- desc => 'Package key'
+ pkg_key => {
+ type => Params::Validate::SCALAR,
+ optional => 1,
+ desc => 'Package key'
},
- trigger_key =>
- { type => Params::Validate::SCALAR,
- optional => 1,
- desc => 'Trigger key'
+ trigger_key => {
+ type => Params::Validate::SCALAR,
+ optional => 1,
+ desc => 'Trigger key'
},
- value =>
- { optional => 1,
- desc => 'Callback value'
+ value => {
+ optional => 1,
+ desc => 'Callback value'
},
- );
+
+ requester => {
+ optional => 1,
+ desc => 'Requesting object'
+ }
+);
sub new {
my $proto = shift;
@@ -481,6 +485,15 @@ passed one to C<< Params::CallbackRequest->request >>. This will be most
useful in a mod_perl environment, of course. Use Apache:FakeRequest in
tests to emmulate the behavior of an Apache request object.
+=head3 requester
+
+ my $r = $cb->requester;
+
+Returns the object that executed the callback by calling C<request()> on a
+Params::CallbackRequest object. Only available if the C<requester> parameter
+is passed to C<< Params::CallbackRequest->request >>. This can be useful for
+callbacks to get access to the object that executed the callbacks.
+
=head3 priority
my $priority = $cb->priority;
View
@@ -1,6 +1,6 @@
#!perl -w
-# $Id: 06object_request.t,v 1.3 2003/10/08 19:27:06 david Exp $
+# $Id$
use strict;
use Test::More;
@@ -17,7 +17,7 @@ BEGIN {
unless eval { require Attribute::Handlers }
and eval { require Class::ISA };
- plan tests => 44;
+ plan tests => 48;
$base_key = 'OOTester';
}
@@ -62,6 +62,13 @@ sub pre_post : Callback {
$params->{chk_post} = 1;
}
+sub requestit : Callback {
+ my $self = shift;
+ my $value = $self->value;
+ my $requester = $self->requester;
+ main::is ref $requester || $requester, $value, "Request is '$value'";
+}
+
sub chk_post : PostCallback {
my $self = shift;
my $params = $self->params;
@@ -198,6 +205,15 @@ is( $params{result}, 'TAKE ME UP AGAIN! Overridden PreCallback PostCallback',
ok( $cb_request->request(\%params), "Execute attribute check callback" );
is( $params{result}, 'Attributes okay', "Check attribute check result" );
+##############################################################################
+# Check that requester is properly passed.
+%params = ("$base_key|requestit_cb" => 'foo');
+ok( $cb_request->request(\%params, requester => 'foo'),
+ "Execute request callback" );
+%params = ("$base_key|requestit_cb" => ref $cb_request );
+ok( $cb_request->request(\%params, requester => $cb_request ),
+ "Execute request as object callback" );
+
1;
__END__

0 comments on commit 754dfcd

Please sign in to comment.