Permalink
Browse files

Reformatting, svn link.

  • Loading branch information...
theory committed May 3, 2008
1 parent 518ca1e commit 59384ed3bd1f9fb5479e4420d3e709b4676ee382
Showing with 114 additions and 97 deletions.
  1. +2 −0 Changes
  2. +32 −28 lib/Params/Callback.pm
  3. +40 −33 lib/Params/CallbackRequest.pm
  4. +40 −36 lib/Params/CallbackRequest/Exceptions.pm
View
@@ -2,6 +2,8 @@ Revision history for Perl extension Params::CallbackRequest.
1.18
- Updated POD test to take advantage of Test::Pod 1.20 or later.
+ - Reformatted the code a bit.
+ - Added a link to the Subversion repository.
1.17 2007-03-27T16:21:34
- Updated copyright date.
View
@@ -36,15 +36,17 @@ BEGIN {
}
# Build read-only accessors.
- for my $attr (qw( cb_request
- params
- apache_req
- priority
- cb_key
- pkg_key
- requester
- trigger_key
- value )) {
+ for my $attr (qw(
+ cb_request
+ params
+ apache_req
+ priority
+ cb_key
+ pkg_key
+ requester
+ trigger_key
+ value
+ )) {
no strict 'refs';
*{$attr} = sub { $_[0]->{$attr} };
}
@@ -116,16 +118,17 @@ sub register_subclass {
my $class = caller;
return unless UNIVERSAL::isa($class, __PACKAGE__)
and $class ne __PACKAGE__;
- my $spec = { default_priority =>
- { type => Params::Validate::SCALAR,
- optional => 1,
- callbacks => $is_num
- },
- class_key =>
- { type => Params::Validate::SCALAR,
- optional => 1
- },
- };
+ my $spec = {
+ default_priority => {
+ type => Params::Validate::SCALAR,
+ optional => 1,
+ callbacks => $is_num
+ },
+ class_key => {
+ type => Params::Validate::SCALAR,
+ optional => 1
+ },
+ };
my %p = Params::Validate::validate(@_, $spec);
@@ -160,12 +163,13 @@ sub Callback : ATTR(CODE, BEGIN) {
# Validate the arguments. At this point, there's only one allowed,
# priority. This is to set a priority for the callback method that
# overrides that set for the class.
- my $spec = { priority =>
- { type => Params::Validate::SCALAR,
- optional => 1,
- callbacks => $is_num
- },
- };
+ my $spec = {
+ priority => {
+ type => Params::Validate::SCALAR,
+ optional => 1,
+ callbacks => $is_num
+ },
+ };
my %p = Params::Validate::validate(@$data, $spec);
# Get the priority.
my $priority = exists $p{priority} ? $p{priority} :
@@ -320,9 +324,9 @@ sub _load_classes {
# Process the class keys in the order they're given, or just do all of
# them if $ckeys eq 'ALL' or $ckeys->[0] eq '_ALL_' (checked by
# Params::CallbackRequest).
- foreach my $ckey (ref $ckeys && $ckeys->[0] ne '_ALL_'
- ? @$ckeys
- : keys %classes) {
+ foreach my $ckey (
+ ref $ckeys && $ckeys->[0] ne '_ALL_' ? @$ckeys : keys %classes
+ ) {
my $class = $classes{$ckey} or
die "Class with class key '$ckey' not loaded. Did you forget use"
. " it or to call register_subclass()?";
@@ -44,54 +44,56 @@ my $exception_handler = sub {
};
# Set up the valid parameters to new().
-my %valid_params =
- ( default_priority =>
- { type => Params::Validate::SCALAR,
- callbacks => { 'valid priority' => sub { $_[0] =~ /^\d$/ } },
- default => 5,
+my %valid_params = (
+ default_priority => {
+ type => Params::Validate::SCALAR,
+ callbacks => {
+ 'valid priority' => sub { $_[0] =~ /^\d$/ }
+ },
+ default => 5,
},
- default_pkg_key =>
- { type => Params::Validate::SCALAR,
- default => 'DEFAULT',
+ default_pkg_key => {
+ type => Params::Validate::SCALAR,
+ default => 'DEFAULT',
},
- callbacks =>
- { type => Params::Validate::ARRAYREF,
- optional => 1,
+ callbacks => {
+ type => Params::Validate::ARRAYREF,
+ optional => 1,
},
- pre_callbacks =>
- { type => Params::Validate::ARRAYREF,
- optional => 1,
+ pre_callbacks => {
+ type => Params::Validate::ARRAYREF,
+ optional => 1,
},
- post_callbacks =>
- { type => Params::Validate::ARRAYREF,
- optional => 1,
+ post_callbacks => {
+ type => Params::Validate::ARRAYREF,
+ optional => 1,
},
- cb_classes =>
- { type => Params::Validate::ARRAYREF | Params::Validate::SCALAR,
- callbacks => { 'valid cb_classes' => $valid_cb_classes },
- optional => 1,
+ cb_classes => {
+ type => Params::Validate::ARRAYREF | Params::Validate::SCALAR,
+ callbacks => { 'valid cb_classes' => $valid_cb_classes },
+ optional => 1,
},
- ignore_nulls =>
- { type => Params::Validate::BOOLEAN,
- default => 0,
+ ignore_nulls => {
+ type => Params::Validate::BOOLEAN,
+ default => 0,
},
- exception_handler =>
- { type => Params::Validate::CODEREF,
- default => $exception_handler
+ exception_handler => {
+ type => Params::Validate::CODEREF,
+ default => $exception_handler
},
- leave_notes =>
- { type => Params::Validate::BOOLEAN,
- default => 0,
+ leave_notes => {
+ type => Params::Validate::BOOLEAN,
+ default => 0,
},
- );
+);
BEGIN {
# Load up any callback class definitions.
@@ -1008,9 +1010,14 @@ he borrowed from Paul Lindner's work with Apache::ASP. My thanks to them both
for planting this great idea! This implementation is however completely
independent of previous implementations.
-=head1 BUGS
+=head1 SUPPORT
+
+This module is stored in an open repository at the following address:
+
+L<https://svn.kineticode.com/Params-CallbackRequest/trunk/>
-Please send bug reports to <bug-params-callbackrequest@rt.cpan.org>.
+Patches against SVN::Notify are welcome. Please send bug reports to
+<bug-params-callbackrequest@rt.cpan.org>.
=head1 SEE ALSO
@@ -4,55 +4,59 @@ use strict;
use vars qw($VERSION);
$VERSION = '1.18';
-use Exception::Class ( 'Params::Callback::Exception' =>
- { description => 'Params::Callback exception',
- alias => 'throw_cb' },
-
- 'Params::Callback::Exception::InvalidKey' =>
- { isa => 'Params::Callback::Exception',
- description => 'No callback found for callback key',
- alias => 'throw_bad_key',
- fields => [ qw(callback_key) ] },
-
- 'Params::Callback::Exception::Execution' =>
- { isa => 'Params::Callback::Exception',
- description => 'Error thrown by callback',
- alias => 'throw_cb_exec',
- fields => [ qw(callback_key callback_error) ] },
-
- 'Params::Callback::Exception::Params' =>
- { isa => 'Params::Callback::Exception',
- description => 'Invalid parameter',
- alias => 'throw_bad_params',
- fields => [ qw(param) ] },
-
- 'Params::Callback::Exception::Abort' =>
- { isa => 'Params::Callback::Exception',
- fields => [qw(aborted_value)],
- alias => 'throw_abort',
- description => 'a callback called abort()' },
- );
+use Exception::Class (
+ 'Params::Callback::Exception' => {
+ description => 'Params::Callback exception',
+ alias => 'throw_cb'
+ },
+
+ 'Params::Callback::Exception::InvalidKey' => {
+ isa => 'Params::Callback::Exception',
+ description => 'No callback found for callback key',
+ alias => 'throw_bad_key',
+ fields => [qw(callback_key)]
+ },
+
+ 'Params::Callback::Exception::Execution' => {
+ isa => 'Params::Callback::Exception',
+ description => 'Error thrown by callback',
+ alias => 'throw_cb_exec',
+ fields => [qw(callback_key callback_error)]
+ },
+
+ 'Params::Callback::Exception::Params' => {
+ isa => 'Params::Callback::Exception',
+ description => 'Invalid parameter',
+ alias => 'throw_bad_params',
+ fields => [qw(param)]
+ },
+
+ 'Params::Callback::Exception::Abort' => {
+ isa => 'Params::Callback::Exception',
+ fields => [qw(aborted_value)],
+ alias => 'throw_abort',
+ description => 'a callback called abort()'
+ },
+);
sub import {
my ($class, %args) = @_;
my $caller = caller;
if ($args{abbr}) {
- foreach my $name (@{$args{abbr}}) {
- no strict 'refs';
- die "Unknown exception abbreviation '$name'"
- unless defined &{$name};
- *{"${caller}::$name"} = \&{$name};
- }
+ foreach my $name (@{$args{abbr}}) {
+ no strict 'refs';
+ die "Unknown exception abbreviation '$name'"
+ unless defined &{$name};
+ *{"${caller}::$name"} = \&{$name};
+ }
}
no strict 'refs';
*{"${caller}::isa_cb_exception"} = \&isa_cb_exception;
*{"${caller}::rethrow_exception"} = \&rethrow_exception;
}
-
-
sub isa_cb_exception ($;$) {
my ($err, $name) = @_;
return unless defined $err;

0 comments on commit 59384ed

Please sign in to comment.