X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Fwith.git;a=blobdiff_plain;f=lib%2Fwith.pm;fp=lib%2Fwith.pm;h=09de93f1c7ba5926fe8a516d32f79bec01d93183;hp=878f8f6e1fc30c3338814512e57c4a4b869ba3d1;hb=faafb12810e0a10b845ecc4bc53c477bc09bc37b;hpb=2a83dd9e0f60cd533826846570869c73789f8192 diff --git a/lib/with.pm b/lib/with.pm index 878f8f6..09de93f 100644 --- a/lib/with.pm +++ b/lib/with.pm @@ -63,7 +63,9 @@ our $VERSION = '0.02'; =head1 DESCRIPTION -This pragma lets you define a default object against with methods will be called in the current scope when possible. It is enabled by the C idiom (note that you must pass a reference to the object). If you C several times in the current scope, the default object will be the last specified one. +This pragma lets you define a default object against with methods will be called in the current scope when possible. +It is enabled by the C idiom (note that you must pass a reference to the object). +If you C several times in the current scope, the default object will be the last specified one. =cut @@ -306,9 +308,16 @@ sub unimport { The main problem to address is that lexical scoping and source modification can only occur at compile time, while object creation and method resolution happen at run-time. -The C statement stores an address to the variable C<$obj> in the C field of the hints hash C<%^H>. It also starts a source filter that replaces function calls with calls to C, passing the name of the original function as the first argument. When the replaced function has a prototype or is part of the core, the call is deferred to a corresponding wrapper generated in the C namespace. Some keywords that couldn't possibly be replaced are also completely skipped. C undefines the hint and deletes the source filter, stopping any subsequent modification in the current scope. +The C statement stores an address to the variable C<$obj> in the C field of the hints hash C<%^H>. +It also starts a source filter that replaces function calls with calls to C, passing the name of the original function as the first argument. +When the replaced function has a prototype or is part of the core, the call is deferred to a corresponding wrapper generated in the C namespace. +Some keywords that couldn't possibly be replaced are also completely skipped. +C undefines the hint and deletes the source filter, stopping any subsequent modification in the current scope. -When the script is executed, deferred calls first fetch the default object back from the address stored into the hint. If the object C<< ->can >> the original function name, a method call is issued. If not, the calling namespace is inspected for a subroutine with the proper name, and if it's present the program Cs into it. If that fails too, the core function with the same name is recalled if possible, or an "Undefined subroutine" error is thrown. +When the script is executed, deferred calls first fetch the default object back from the address stored into the hint. +If the object C<< ->can >> the original function name, a method call is issued. +If not, the calling namespace is inspected for a subroutine with the proper name, and if it's present the program Cs into it. +If that fails too, the core function with the same name is recalled if possible, or an "Undefined subroutine" error is thrown. =head1 IGNORED KEYWORDS @@ -328,11 +337,17 @@ No function or constant is exported by this pragma. =head1 CAVEATS -Most likely slow. Almost surely non thread-safe. Contains source filters, hence brittle. Messes with the dreadful prototypes. Crazy. Will have bugs. +Most likely slow. +Almost surely non thread-safe. +Contains source filters, hence brittle. +Messes with the dreadful prototypes. +Crazy. +Will have bugs. Don't put anything on the same line of C or C. -When there's a function in the caller namespace that has a core function name, and when no method with the same name is present, the ambiguity is resolved in favor of the caller namespace. That's different from the usual perl semantics where C gets resolved to CORE::push. +When there's a function in the caller namespace that has a core function name, and when no method with the same name is present, the ambiguity is resolved in favor of the caller namespace. +That's different from the usual perl semantics where C gets resolved to CORE::push. If a method has the same name as a prototyped function in the caller namespace, and if a called is deferred to the method, it will have its arguments passed by value. @@ -354,7 +369,8 @@ You can contact me by mail or on C (vincent). =head1 BUGS -Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. +Please report any bugs or feature requests to C, or through the web interface at L. +I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT