[poe-commits] SF.net SVN: poe: [2122] trunk/poe
Brought to you by:
rcaputo
From: <lo...@us...> - 2006-09-08 20:28:27
|
Revision: 2122 http://svn.sourceforge.net/poe/?rev=2122&view=rev Author: lotr Date: 2006-09-08 13:28:16 -0700 (Fri, 08 Sep 2006) Log Message: ----------- document instantiate and try_alloc, and thus remove them from the exception list in tests/10_units/01_pod/02_pod_coverage.t Modified Paths: -------------- trunk/poe/lib/POE/Session.pm trunk/poe/tests/10_units/01_pod/02_pod_coverage.t Modified: trunk/poe/lib/POE/Session.pm =================================================================== --- trunk/poe/lib/POE/Session.pm 2006-09-08 16:23:04 UTC (rev 2121) +++ trunk/poe/lib/POE/Session.pm 2006-09-08 20:28:16 UTC (rev 2122) @@ -1237,6 +1237,51 @@ =back +=head2 Subclassing + +There are a few methods available to help people trying to subclass +L<POE::Session>. + +=over 2 + +=item instantiate + +When you want to subclass L<POE::Session>, you may want to allow for extra +parameters to be passed to the constructor, and maybe store some extra data +in the object structure. + +The easiest way to do this is by overriding the instantiate method, which +creates an empty object for you, and is passed a reference to the hash of +parameters passed to create(). + +When overriding it, be sure to first call the parent classes instantiate +method, so you have a reference to the empty object. Then you should remove +all the extra parameters from the hash of parameters you get passed, so +L<POE::Session>'s create() doesn't croak when it encounters parameters it +doesn't know. + +Also, don't forget to return the reference to the object (optionally already +filled with your data; try to keep out of the places where L<POE::Session> +stores its stuff, or it'll get overwritten) + +=item try_alloc + +At the end of L<POE::Session>'s create() method, try_alloc() is called. +This tells the POE Kernel to allocate an actual session with the object +just created. + +If you want to fiddle with the object the constructor just created, to +modify parameters that already exist in the base L<POE::Session> class, +based on your extra parameters for example, this is the place to do it. +override the try_alloc() method, do your evil, and end with calling +the parent try_alloc(), returning its return value. + +try_alloc() is passed the arguments for the _start state (the contents of +the listref passed in the 'args' parameter for create()). Make sure to pass +this on to the parent method (after maybe fiddling with that too). + +=back + =head1 PREDEFINED EVENT FIELDS Each session maintains its unique runtime context. Sessions pass @@ -1717,7 +1762,6 @@ =back - =head1 SEE ALSO POE::Kernel. Modified: trunk/poe/tests/10_units/01_pod/02_pod_coverage.t =================================================================== --- trunk/poe/tests/10_units/01_pod/02_pod_coverage.t 2006-09-08 16:23:04 UTC (rev 2121) +++ trunk/poe/tests/10_units/01_pod/02_pod_coverage.t 2006-09-08 20:28:16 UTC (rev 2122) @@ -46,8 +46,6 @@ ? ( ) : ( 'register_state', # Should become _register_state. - 'instantiate', # Public or private? - 'try_alloc', # Public or private? ) ) ], This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |