From: Vincent Pit Date: Thu, 5 Mar 2009 21:14:32 +0000 (+0100) Subject: This is 0.03 X-Git-Tag: v0.03^0 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLexical-Types.git;a=commitdiff_plain;h=ef454c52e92ecd149b3bf0f6e221162cad3955ac This is 0.03 --- diff --git a/Changes b/Changes index 27412c9..14ab9e1 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,12 @@ Revision history for Lexical-Types +0.03 2009-03-05 21:15 UTC + + Doc : Discuss about using constants for types. + + Fix : The PL_ppaddr[OP_PADSV] localization logic was refined so that + it is kinder to other modules that replace it. + + Tst : "my Str ($x, $y)" and "for my Str $x ()" constructs + + Tst : uvar magic, magical tags. + 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. diff --git a/META.yml b/META.yml index 4e71e0b..72b23ff 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- #YAML:1.0 name: Lexical-Types -version: 0.02 +version: 0.03 abstract: Extend the semantics of typed lexicals. author: - Vincent Pit @@ -9,6 +9,7 @@ distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: + constant: 0 ExtUtils::MakeMaker: 0 Test::More: 0 requires: diff --git a/README b/README index 7e2c99a..bba2ba0 100644 --- a/README +++ b/README @@ -2,21 +2,35 @@ NAME Lexical::Types - Extend the semantics of typed lexicals. VERSION - Version 0.02 + Version 0.03 SYNOPSIS + { package Str; } + + { + package My::Types::Str; + + sub new { bless { }, shift } + } + + use Lexical::Types as => sub { 'My::Types::' . $_[0] => 'new' }; + + my Str $x; # $x is now a My::Types::Str object + { - package Str; + package My::Types::Int; - sub TYPEDSCALAR { Some::String::Implementation->new } + sub TYPEDSCALAR { bless { }, shift } } use Lexical::Types; - my Str $x; # $x is now a Some::String::Implementation object + use constant Int => 'My::Types::Int'; + + my Int $y; # $y is now a My::Types::Int object DESCRIPTION - This module allows you to hook the execution of typed lexicals + This pragma allows you to hook the execution of typed lexicals declarations ("my Str $x"). In particular, it can be used to automatically tie or bless typed lexicals. @@ -49,9 +63,9 @@ FUNCTIONS 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 + use Lexical::Types as => sub { return $_[0] =~ /Str/ ? @_ : () }; + my Str $y; # calls Str->TYPEDSCALAR + my Int $x; # nothing special * or the desired package and method name, in that order (if any of those is "undef", the default value will be used instead). @@ -65,7 +79,7 @@ FUNCTIONS scalar that will be copied into $x. "unimport" - Magically called when writing "no Lexical::Types". Turns the module off. + Magically called when writing "no Lexical::Types". Turns the pragma off. INTEGRATION You can integrate Lexical::Types in your module so that using it will @@ -92,10 +106,15 @@ INTEGRATION sub new_int { ... } CAVEATS - 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. + For "perl" to be able to parse "my Str $x", you need : + + * either the "Str" package to be defined ; + + * or for "Str" to be a constant sub returning a valid defined package. + + Those restrictions apply even if you use the 'as' option to redirect to + another package, and are unlikely to find a workaround as this happens + deep inside the lexer - far from the reach of an extension. Only one mangler or prefix can be in use at the same time in a given scope. @@ -131,6 +150,8 @@ SUPPORT ACKNOWLEDGEMENTS Inspired by Ricardo Signes. + Thanks Florian Ragwitz for suggesting the use of constants for types. + COPYRIGHT & LICENSE Copyright 2009 Vincent Pit, all rights reserved. diff --git a/lib/Lexical/Types.pm b/lib/Lexical/Types.pm index b22c2cc..841c3aa 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.02 +Version 0.03 =cut our $VERSION; BEGIN { - $VERSION = '0.02'; + $VERSION = '0.03'; } =head1 SYNOPSIS