X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2Fwith.pm;h=965e6da442f32ca51f60047967b943521959c596;hb=8aa4d8cae76a921141ab962f2a28f34f82e0d817;hp=54d00c3c4d548bb19a50040424292e6ab3ab7cf4;hpb=d475fd18dbefb0240bd3b07325052cda8f2b8e51;p=perl%2Fmodules%2Fwith.git diff --git a/lib/with.pm b/lib/with.pm index 54d00c3..965e6da 100644 --- a/lib/with.pm +++ b/lib/with.pm @@ -1,16 +1,16 @@ package with; -use 5.009004; +use 5.009_004; use strict; use warnings; -use Carp qw/croak/; +use Carp qw; use Filter::Util::Call; -use Text::Balanced qw/extract_variable extract_quotelike extract_multiple/; -use Scalar::Util qw/refaddr set_prototype/; +use Text::Balanced qw; +use Scalar::Util qw; -use Sub::Prototype::Util qw/flatten wrap/; +use Sub::Prototype::Util qw; =head1 NAME @@ -24,6 +24,12 @@ Version 0.02 our $VERSION = '0.02'; +=head1 WARNING + +This module was an early experiment which turned out to be completely unpractical. +Therefore its use is officially B. +Please don't use it, and don't hesitate to contact me if you want to reuse the namespace. + =head1 SYNOPSIS package Deuce; @@ -47,7 +53,7 @@ our $VERSION = '0.02'; use with \$deuce; hlagh; # Deuce::hlagh 1 Pants::hlagh; # Pants::hlagh - + { use with \Deuce->new(2); hlagh; # Deuce::hlagh 2 @@ -63,7 +69,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 @@ -94,15 +102,15 @@ my $extractor = [ ]; my %skip; -$skip{$_} = 1 for qw/my our local sub do eval goto return - if else elsif unless given when or and +$skip{$_} = 1 for qw; -my @core = qw/abs accept alarm atan2 bind binmode bless caller chdir chmod +my @core = qw; my %core; $core{$_} = prototype "CORE::$_" for @core; @@ -306,16 +314,23 @@ 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 A call will never be dispatched to a method whose name is one of : my our local sub do eval goto return - if else elsif unless given when or and + if else elsif unless given when or and while until for foreach next redo last continue eq ne lt gt le ge cmp map grep system exec sort print say @@ -328,11 +343,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 +375,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