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 st...@apache.org on 2006/11/25 01:24:18 UTC

svn commit: r479056 - /perl/modperl/docs/trunk/src/docs/2.0/user/coding/coding.pod

Author: stas
Date: Fri Nov 24 16:24:17 2006
New Revision: 479056

URL: http://svn.apache.org/viewvc?view=rev&rev=479056
Log:
complete the section on Method Handlers

Modified:
    perl/modperl/docs/trunk/src/docs/2.0/user/coding/coding.pod

Modified: perl/modperl/docs/trunk/src/docs/2.0/user/coding/coding.pod
URL: http://svn.apache.org/viewvc/perl/modperl/docs/trunk/src/docs/2.0/user/coding/coding.pod?view=diff&rev=479056&r1=479055&r2=479056
==============================================================================
--- perl/modperl/docs/trunk/src/docs/2.0/user/coding/coding.pod (original)
+++ perl/modperl/docs/trunk/src/docs/2.0/user/coding/coding.pod Fri Nov 24 16:24:17 2006
@@ -23,30 +23,58 @@
 =head1 Techniques
 
 
-
 =head2 Method Handlers
 
-In mod_perl 2.0 method handlers are declared using the C<method>
-attribute:
+In addition to function handlers method handlers can be used.  Method
+handlers are useful when you want to write code that takes advantage
+of inheritance. To make the handler act as a method under mod_perl 2,
+use the C<method> attribute.
+
+See the Perl I<attributes> manpage for details on the attributes
+syntax (C<perldoc attributes>).
 
-  package Bird;
-  @ISA = qw(Eagle);
+For example:
+
+  package Bird::Eagle;
+  @ISA = qw(Bird);
   
   sub handler : method {
-      my ($class, $r) = @_;
+      my ($class_or_object, $r) = @_;
       ...;
   }
+  
+  sub new { bless {}, __PACKAGE__ }
+
+and then register it as:
+
+  PerlResponseHandler Bird::Eagle
+
+When mod_perl sees that the handler has a method attribute, it passes
+two arguments to it: the calling object or a class, depending on how
+it was called, and the request object, as shown above.
+
+If C<Class-E<gt>method> syntax is used for a C<Perl*Handler>, e.g.:
+
+  PerlResponseHandler Bird::Eagle->handler;
+
+the C<:method> attribute is not required.
+
+In the preceding configuration example, the C<handler()> method will
+be called as a class (static) method.
+
+Also, you can use objects created at startup to call methods. For example:
+
+  <Perl>
+      use Bird::Eagle;
+      $Bird::Global::object = Bird::Eagle->new();
+  </Perl>
+  ...
+  PerlResponseHandler $Bird::Global::object->handler
 
-See the I<attributes> manpage.
+In this example, the C<handler()> method will be called as an instance
+method on the global object $C<Bird::Global::object>.
 
-If C<Class-E<gt>method> syntax is used for a C<Perl*Handler>, the
-C<:method> attribute is not required.
 
-META: need to port the method handlers document from mp1 guide, may be
-keep it as a separate document. Meanwhile refer to L<that
-document|docs::1.0::guide::method_handlers>, though L<replace the C<$$> 
-prototype with the C<:method> attribute
-|docs::2.0::user::porting::compat/Method_Handlers>.
 
 
 =head2 Cleaning up



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