From: Vincent Pit Date: Wed, 25 Feb 2009 16:08:27 +0000 (+0100) Subject: This is 0.02 X-Git-Tag: v0.02^0 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLexical-Types.git;a=commitdiff_plain;h=e291e59267c1f2c400cce6aa9006293ef06fa375 This is 0.02 --- diff --git a/Changes b/Changes index 8a5efa1..27412c9 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,11 @@ Revision history for Lexical-Types +0.02 2009-02-25 16:10 UTC + + Add : Returning an empty list from the mangler skips the wrapping of + the current typed lexical declaration. + + Chg : The package and method names passed to the callbacks are now all + read-only. + 0.01 2009-02-24 23:20 UTC First version, released on an unsuspecting world. diff --git a/META.yml b/META.yml index d0319e4..4e71e0b 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- #YAML:1.0 name: Lexical-Types -version: 0.01 +version: 0.02 abstract: Extend the semantics of typed lexicals. author: - Vincent Pit diff --git a/README b/README index 42aec0e..7e2c99a 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ NAME Lexical::Types - Extend the semantics of typed lexicals. VERSION - Version 0.01 + Version 0.02 SYNOPSIS { @@ -17,7 +17,7 @@ SYNOPSIS DESCRIPTION This module allows you to hook the execution of typed lexicals - declarations ("my Foo $x"). In particular, it can be used to + declarations ("my Str $x"). In particular, it can be used to automatically tie or bless typed lexicals. It is not implemented with a source filter. @@ -25,33 +25,42 @@ DESCRIPTION FUNCTIONS "import [ as => [ $prefix | $mangler ] ]" Magically called when writing "use Lexical::Types". All the occurences - of "my Foo $x" in the current lexical scope will be changed to call at + of "my Str $x" in the current lexical scope will be changed to call at each run a given method in a given package. The method and package are - determined by the parameter "as" : + determined by the parameter 'as' : - * If it's left unspecified, the "TYPEDSCALAR" method in the "Foo" + * If it's left unspecified, the "TYPEDSCALAR" method in the "Str" package will be called. use Lexical::Types; my Str $x; # calls Str->TYPEDSCALAR * If a plain scalar $prefix is passed as the value, the "TYPEDSCALAR" - method in the "${prefix}::Foo" package will be used. + method in the "${prefix}::Str" package will be used. use Lexical::Types as => 'My::'; # or "as => 'My'" my Str $x; # calls My::Str->TYPEDSCALAR * If the value given is a code reference $mangler, it will be called - at compile-time with arguments 'Foo' and 'TYPEDSCALAR' and is - expected to return the desired package and method name (in that - order). If any of those is "undef", the default value will be used - instead. + at compile-time with arguments 'Str' and 'TYPEDSCALAR' and is + expected to return : - use Lexical::Types as => sub { 'My', 'new_' . lc($_[0]) }; - my Str $x; # the coderef indicates to call My->new_str + * either an empty list, in which case the current typed lexical + definition will be skipped (thus it won't be altered to trigger + a run-time hook) ; + + use Lexical::Types as => sub { return $_[0] =~ /Str/ ? () : @_ }; + my Str $x; # nothing special + my Int $y; # calls Int->TYPEDSCALAR + + * or the desired package and method name, in that order (if any of + those is "undef", the default value will be used instead). + + use Lexical::Types as => sub { 'My', 'new_' . lc($_[0]) }; + my Str $x; # the coderef indicates to call My->new_str The initializer method receives an alias to the pad entry of $x in $_[1] - and the original type name ("Foo") in $_[2]. You can either edit $_[1] + and the original type name ("Str") in $_[2]. You can either edit $_[1] in place, in which case you should return an empty list, or return a new scalar that will be copied into $x. @@ -83,8 +92,8 @@ INTEGRATION sub new_int { ... } CAVEATS - For "perl" to be able to parse "my Foo $x", the package "Foo" must be - defined somewhere, and this even if you use the "as" option to redirect + For "perl" to be able to parse "my Str $x", the package "Str" must be + defined somewhere, and this even if you use the 'as' option to redirect to another package. It's unlikely to find a workaround, as this happens deep inside the lexer, far from the reach of an extension. diff --git a/lib/Lexical/Types.pm b/lib/Lexical/Types.pm index a773751..f3ff14d 100644 --- a/lib/Lexical/Types.pm +++ b/lib/Lexical/Types.pm @@ -13,13 +13,13 @@ Lexical::Types - Extend the semantics of typed lexicals. =head1 VERSION -Version 0.01 +Version 0.02 =cut our $VERSION; BEGIN { - $VERSION = '0.01'; + $VERSION = '0.02'; } =head1 SYNOPSIS