You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs-cvs@perl.apache.org by ra...@apache.org on 2005/05/06 16:11:19 UTC

svn commit: r168603 - /perl/modperl/docs/trunk/src/docs/2.0/api/APR/Status.pod

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.

Modified:
    perl/modperl/docs/trunk/src/docs/2.0/api/APR/Status.pod

Modified: perl/modperl/docs/trunk/src/docs/2.0/api/APR/Status.pod
URL: http://svn.apache.org/viewcvs/perl/modperl/docs/trunk/src/docs/2.0/api/APR/Status.pod?rev=168603&r1=168602&r2=168603&view=diff
==============================================================================
--- perl/modperl/docs/trunk/src/docs/2.0/api/APR/Status.pod (original)
+++ perl/modperl/docs/trunk/src/docs/2.0/api/APR/Status.pod Fri May  6 07:11:18 2005
@@ -98,6 +98,80 @@
 C<APR::Const::EAGAIN> unless you know what you are doing.
 
 
+=head2 C<is_EACCES>
+
+Check if the error is matching C<EACCES> and its variants (corresponds
+to the C<APR_STATUS_IS_EACCES> macro).
+
+  $status = APR::Status::is_EACCES($error_code);
+
+=over 4
+
+=item arg1: C<$error_code> (integer or C<L<APR::Error
+object|docs::2.0::api::APR::Error>> )
+
+The error code or to check, normally C<$@> blessed into C<L<APR::Error
+object|docs::2.0::api::APR::Error>>.
+
+=item ret: C<$status> ( boolean )
+
+=item since: 1.999.24
+
+=back
+
+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;
+      }
+  }
+
+As discussed above with C<APR::Const::EAGAIN>, the advantage of
+using C<is_EACCES> is portability - just checking
+C<$@> against C<APR::Const::EACCES> may work on some unices,
+but could fail on other platforms. 
+
+
+=head2 C<is_ENOENT>
+
+Check if the error is matching C<ENOENT> and its variants (corresponds
+to the C<APR_STATUS_IS_ENOENT> macro).
+
+  $status = APR::Status::is_ENOENT($error_code);
+
+=over 4
+
+=item arg1: C<$error_code> (integer or C<L<APR::Error
+object|docs::2.0::api::APR::Error>> )
+
+The error code or to check, normally C<$@> blessed into C<L<APR::Error
+object|docs::2.0::api::APR::Error>>.
+
+=item ret: C<$status> ( boolean )
+
+=item since: 1.999.24
+
+=back
+
+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;
+      }
+  }
+
 
 =head1 See Also
 



---------------------------------------------------------------------
To unsubscribe, e-mail: docs-cvs-unsubscribe@perl.apache.org
For additional commands, e-mail: docs-cvs-help@perl.apache.org


Re: svn commit: r168603 - /perl/modperl/docs/trunk/src/docs/2.0/api/APR/Status.pod

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> 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.

And there are more places that need to be adjusted to use the new API, 
e.g.: the Apache2::RequestUtil manpage goes:

----------------------
Possible error codes could be:
C<L<APR::Const::EACCES|docs::2.0::api::APR::Const/C_APR__EACCES_>>
(permission problems),
C<L<APR::Const::ENOENT|docs::2.0::api::APR::Const/C_APR__ENOENT_>> (file not
found) and others.
----------------------

Probably others too. Try to grep for the above two constants?

Thanks.

-- 
__________________________________________________________________
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


Re: svn commit: r168603 - /perl/modperl/docs/trunk/src/docs/2.0/api/APR/Status.pod

Posted by Stas Bekman <st...@stason.org>.
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