randyk@apache.org wrote:
> Author: randyk
> Date: Fri May 6 07:11:18 2005
> New Revision: 168603
>
> URL: http://svn.apache.org/viewcvs?rev=168603&view=rev
> Log:
> add documentation for APR::Status::is_EACCES and APR::Status::is_ENOENT.
[...]
> +An example of using C<is_EACCES> is when reading the contents of a
> +file where access may be forbidden:
> +
> + eval { $obj->slurp_filename(0) };
> + if ($@) {
> + if (ref $@ eq 'APR::Error') {
> + return Apache2::Const::FORBIDDEN if APR::Status::is_EACCES($@);
> + }
> + else {
> + return Apache2::Const::SERVER_ERROR;
> + }
> + }
there is a flow in your example, Randy: what if APR::Status::is_EACCES is
not true? Nothing handles that case -- it silently falls through.
Also I think it's always the bests to re-throw the error if you don't
handle it, so it could be:
eval { $obj->slurp_filename(0) };
if ($@) {
return Apache2::Const::FORBIDDEN
if ref $@ eq 'APR::Error' && APR::Status::is_EACCES($@);
die @; #re-throw
}
but at least it has to be:
> + if ($@) {
> + if (ref $@ eq 'APR::Error' && APR::Status::is_EACCES($@)) {
> + return Apache2::Const::FORBIDDEN;
> + }
> + else {
> + return Apache2::Const::SERVER_ERROR;
> + }
> + }
Please choose whatever you prefer.
and the same here (flowed example):
> +An example of using C<is_ENOENT> is when reading the contents of a
> +file which may not exist:
> +
> + eval { $obj->slurp_filename(0) };
> + if ($@) {
> + if (ref $@ eq 'APR::Error') {
> + return Apache2::Const::NOT_FOUND if APR::Status::is_ENOENT($@);
> + }
> + else {
> + return Apache2::Const::SERVER_ERROR;
> + }
> + }
Thanks Randy.
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-dev-unsubscribe@perl.apache.org
For additional commands, e-mail: docs-dev-help@perl.apache.org
> Author: randyk
> Date: Fri May 6 07:11:18 2005
> New Revision: 168603
>
> URL: http://svn.apache.org/viewcvs?rev=168603&view=rev
> Log:
> add documentation for APR::Status::is_EACCES and APR::Status::is_ENOENT.
[...]
> +An example of using C<is_EACCES> is when reading the contents of a
> +file where access may be forbidden:
> +
> + eval { $obj->slurp_filename(0) };
> + if ($@) {
> + if (ref $@ eq 'APR::Error') {
> + return Apache2::Const::FORBIDDEN if APR::Status::is_EACCES($@);
> + }
> + else {
> + return Apache2::Const::SERVER_ERROR;
> + }
> + }
there is a flow in your example, Randy: what if APR::Status::is_EACCES is
not true? Nothing handles that case -- it silently falls through.
Also I think it's always the bests to re-throw the error if you don't
handle it, so it could be:
eval { $obj->slurp_filename(0) };
if ($@) {
return Apache2::Const::FORBIDDEN
if ref $@ eq 'APR::Error' && APR::Status::is_EACCES($@);
die @; #re-throw
}
but at least it has to be:
> + if ($@) {
> + if (ref $@ eq 'APR::Error' && APR::Status::is_EACCES($@)) {
> + return Apache2::Const::FORBIDDEN;
> + }
> + else {
> + return Apache2::Const::SERVER_ERROR;
> + }
> + }
Please choose whatever you prefer.
and the same here (flowed example):
> +An example of using C<is_ENOENT> is when reading the contents of a
> +file which may not exist:
> +
> + eval { $obj->slurp_filename(0) };
> + if ($@) {
> + if (ref $@ eq 'APR::Error') {
> + return Apache2::Const::NOT_FOUND if APR::Status::is_ENOENT($@);
> + }
> + else {
> + return Apache2::Const::SERVER_ERROR;
> + }
> + }
Thanks Randy.
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-dev-unsubscribe@perl.apache.org
For additional commands, e-mail: docs-dev-help@perl.apache.org