Stas Bekman wrote:
Philippe M. Chiasson wrote:
In trying to make sense of Apache::CmdParms->limited() I realized it was
mainly useless to expose, and that there was a method ap_method_is_limited()
designed for that exact purpose.
So the following patch removed the parms->limited field and replaces it
with ap_method_is_limited().
+1
For consistency, I suggest making the Apache::MethodList class available.
For consistency with what? What do we need this class for?
For nothing, really. I must apologize for the confusion. I started trying to get ->limited to work, and for that, I needed to open up Apache::MethodList.
I abandonned that effort too late for a simpler implementation of ap_method_is_limited().
Attached are the 2 patches, separated. (The second one possibly usefull in the future if/when we decide we need Apache::MethodList)
Thoughts ?
Index: docs/api/Apache/CmdParms.pod ===================================================================
# which methods are <Limit>ed ? - $limit = $parms->limited; + $limit = $parms->method_is_limited('GET');
here and below, a more suitable return var name should be used, e.g. is_limited
- $limit = $parms->limited; + $limit = $parms->method_is_limited($method);
+=item ret: C<$limit> ( boolean )
-- -------------------------------------------------------------------------------- Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5 http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
Index: docs/api/Apache/CmdParms.pod
===================================================================
RCS file: /home/cvs/modperl-docs/src/docs/2.0/api/Apache/CmdParms.pod,v
retrieving revision 1.8
diff -u -I$Id -r1.8 CmdParms.pod
--- docs/api/Apache/CmdParms.pod 14 Aug 2004 04:15:25 -0000 1.8
+++ docs/api/Apache/CmdParms.pod 17 Aug 2004 23:17:20 -0000
@@ -30,7 +30,7 @@
$info = $parms->info;
# which methods are <Limit>ed ?
- $limit = $parms->limited;
+ $is_limited = $parms->method_is_limited('GET');
# which allow-override bits are set
$override = $parms->override;
@@ -178,28 +178,33 @@
-=head2 C<limited>
+=head2 C<method_is_limited>
-Which methods are currently E<lt>LimitE<gt>ed
+Discover if a method is E<lt>LimitE<gt>ed in the current scope
- $limit = $parms->limited;
+ $is_limited = $parms->method_is_limited($method);
=over 4
=item obj: C<$parms>
( C<L<Apache::CmdParms object|docs::2.0::api::Apache::CmdParms>> )
-=item ret: C<$limit> ( integer )
+=item arg1: C<$method> (string)
-=item since: 1.99_12
+The name of the method to check for
+
+=item ret: C<$is_limited> ( boolean )
+
+=item since: 1.99_15
=back
- META: and how exactly is it supposed to be used, should this be
- tested against $r->method_number (e.g. Apache::M_POST) ? what's
- $limit? (notice that the test of this method isn't so good, it
- tests some hardcoded -1 value, how do you know that it does what you
- think it does?)
+For example, to check if the C<GET> method is being E<lt>LimitE<gt>ed
+in the current scope, do:
+
+ if ($parms->method_is_limited('GET') {
+ die "...";
+ }
Index: t/response/TestDirective/cmdparms.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestDirective/cmdparms.pm,v
retrieving revision 1.6
diff -u -I$Id -r1.6 cmdparms.pm
--- t/response/TestDirective/cmdparms.pm 14 Aug 2004 05:20:19 -0000 1.6
+++ t/response/TestDirective/cmdparms.pm 17 Aug 2004 23:17:20 -0000
@@ -35,7 +35,7 @@
},
);
-my @methods = qw(cmd context directive info limited override path
+my @methods = qw(cmd context directive info override path
pool server temp_pool);
sub TestCmdParms {
@@ -46,6 +46,8 @@
}
$srv_cfg->{$args}{check_ctx} =
$parms->check_cmd_context(Apache::NOT_IN_LOCATION);
+
+ $srv_cfg->{$args}{limited} = $parms->method_is_limited('GET');
}
sub get_config {
@@ -59,7 +61,7 @@
my $override;
my $srv_cfg = $self->get_config($r->server);
- plan $r, tests => 6 + ( 8 * keys(%$srv_cfg) );
+ plan $r, tests => 9 + ( 7 * keys(%$srv_cfg) );
foreach my $cfg (values %$srv_cfg) {
ok t_cmp(ref($cfg->{cmd}), 'Apache::Command', 'cmd');
@@ -68,7 +70,6 @@
ok t_cmp(ref($cfg->{pool}), 'APR::Pool', 'pool');
ok t_cmp(ref($cfg->{temp_pool}), 'APR::Pool', 'temp_pool');
ok t_cmp(ref($cfg->{server}), 'Apache::ServerRec', 'server');
- ok t_cmp($cfg->{limited}, -1, 'limited');
ok t_cmp($cfg->{info}, 'cmd_data', 'cmd_data');
}
@@ -85,6 +86,7 @@
ok t_cmp($masked, $wanted, 'override bitmask');
ok t_cmp($vhost->{path}, undef, 'path');
ok t_cmp($vhost->{check_ctx}, undef, 'check_cmd_ctx');
+ ok $vhost->{limited};
}
# Location
@@ -103,6 +105,13 @@
ok t_cmp($loc->{path}, '/TestDirective__cmdparms', 'path');
ok t_cmp($loc->{check_ctx}, KEY .
' cannot occur within <Location> section', 'check_cmd_ctx');
+ ok $loc->{limited};
+ }
+
+ # Limit
+ {
+ my $limit = $srv_cfg->{Limit};
+ ok !$limit->{limited};
}
return Apache::OK;
@@ -119,3 +128,7 @@
</Base>
TestCmdParms "Location"
+
+<LimitExcept GET>
+ TestCmdParms "Limit"
+</LimitExcept>
Index: xs/maps/apache_structures.map
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/maps/apache_structures.map,v
retrieving revision 1.44
diff -u -I$Id -r1.44 apache_structures.map
--- xs/maps/apache_structures.map 17 Aug 2004 22:51:24 -0000 1.44
+++ xs/maps/apache_structures.map 17 Aug 2004 23:17:20 -0000
@@ -234,7 +234,7 @@
<cmd_parms>
- info
< override
-< limited
+! limited
! limited_xmethods
! xlimited
! config_file
Index: xs/maps/modperl_functions.map
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/maps/modperl_functions.map,v
retrieving revision 1.82
diff -u -I$Id -r1.82 modperl_functions.map
--- xs/maps/modperl_functions.map 11 Aug 2004 23:03:17 -0000 1.82
+++ xs/maps/modperl_functions.map 17 Aug 2004 23:17:20 -0000
@@ -145,6 +145,7 @@
MODULE=Apache::CmdParms
ap_check_cmd_context
+ ap_method_is_limited
mpxs_Apache__CmdParms_info
MODULE=Apache::MPM PACKAGE=Apache::MPM BOOT=1
Index: xs/maps/apache_functions.map
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/maps/apache_functions.map,v
retrieving revision 1.96
diff -u -I$Id -r1.96 apache_functions.map
--- xs/maps/apache_functions.map 17 Aug 2004 22:51:24 -0000 1.96
+++ xs/maps/apache_functions.map 17 Aug 2004 23:13:14 -0000
@@ -346,16 +346,17 @@
ap_stripprefix
-ap_str_tolower
-!MODULE=Apache::MethodList
+MODULE=Apache::MethodList
ap_clear_method_list
-ap_copy_method_list
- ap_make_method_list
- ap_method_in_list
- ap_method_is_limited
+ ap_make_method_list | | p, nelts=2
+PREFIX=ap_method_list_
ap_method_list_add
- ap_method_list_do
+!ap_method_list_do
ap_method_list_remove
- ap_method_list_vdo
+!ap_method_list_vdo
+PREFIX=ap_method_
+ ap_method_in_list
ap_method_name_of
ap_method_number_of
Index: t/response/TestAPI/method_list.pm
===================================================================
RCS file: t/response/TestAPI/method_list.pm
diff -N t/response/TestAPI/method_list.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/response/TestAPI/method_list.pm 17 Aug 2004 23:13:14 -0000
@@ -0,0 +1,55 @@
+package TestAPI::method_list;
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::MethodList ();
+
+use Apache::Test;
+use Apache::TestUtil;
+
+use Apache::Const -compile => qw(OK M_GET M_PUT M_POST);
+
+my %methods = (
+ 'GET' => Apache::M_GET,
+ 'POST' => Apache::M_POST,
+ 'PUT' => Apache::M_PUT,
+);
+
+my @fake_methods = qw(ONE TWO THREE FOUR FIVE);
+
+sub handler : method {
+ my($self, $r) = @_;
+
+ plan $r, tests => 2 + ( 2 * keys %methods) + ( 2 * @fake_methods);
+
+ while ( my ($name, $value) = each %methods ) {
+ ok t_cmp Apache::MethodList::number_of($name), $methods{$name}, "number_of:$name";
+ ok t_cmp Apache::MethodList::name_of($r->pool, $value), $name, "name_of:$name";
+ }
+
+ my $list = Apache::MethodList::make_method_list($r->pool);
+
+ ok t_cmp ref($list), "Apache::MethodList", "make_method_list";
+
+ foreach my $m (@fake_methods) {
+ $list->add($m);
+ }
+
+ foreach my $m (@fake_methods) {
+ ok t_cmp $list->in_list($m), 1, "$m in list";
+ $list->remove($m);
+ }
+
+ foreach my $m (@fake_methods) {
+ ok t_cmp $list->in_list($m), 0, "$m not in list";
+ $list->remove($m);
+ }
+
+ ok $list->clear_method_list || 1;
+
+ return Apache::OK;
+}
+
+1;
+__END__
Index: t/api/.cvsignore
===================================================================
RCS file: /home/cvs/modperl-2.0/t/api/.cvsignore,v
retrieving revision 1.16
diff -u -I$Id -r1.16 .cvsignore
--- t/api/.cvsignore 14 Aug 2004 05:23:50 -0000 1.16
+++ t/api/.cvsignore 17 Aug 2004 23:13:14 -0000
@@ -4,6 +4,7 @@
conn_rec.t
conn_util.t
lookup_uri2.t
+method_list.t
module.t
process.t
query.t
signature.asc
Description: OpenPGP digital signature
