X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FLexical%2FTypes.pm;h=c5c416b97f53da70db2d906db7fd4c91f8d11059;hb=cd8d951930816a806c3c5913fdea42dce49cc581;hp=36960d88603cac0621c2a7620332192b8990c93a;hpb=f693737e7e11807a5386bdf639cf620367333be3;p=perl%2Fmodules%2FLexical-Types.git diff --git a/lib/Lexical/Types.pm b/lib/Lexical/Types.pm index 36960d8..c5c416b 100644 --- a/lib/Lexical/Types.pm +++ b/lib/Lexical/Types.pm @@ -127,9 +127,6 @@ or the desired package and method name, in that order (if any of those is C in C<$_[1]> and the original type name (C) in C<$_[2]>. -You can either edit C<$_[1]> in place, in which case you should return an empty list, or return a new scalar that will be copied into C<$x>. - =cut sub import { @@ -170,6 +167,22 @@ sub unimport { $^H{+(__PACKAGE__)} = undef; } +=head1 RUN-TIME INITIALIZER METHOD + +The initializer method receives an alias to the pad slot of the initialized lexical in C<$_[1]> and the original type name in C<$_[2]>. +You can either edit C<$_[1]> in place, in which case you should return an empty list, or return a new scalar that will be copied into the pad slot. + + use Lexical::Types as => 'My'; + + my Str $x; + + ... + + sub My::Str::TYPEDSCALAR { + # $_[1] is an alias to $x, and $_[2] is 'Str' + ... + } + =head1 INTEGRATION You can integrate L in your module so that using it will provide types to your users without asking them to load either L or the type classes manually.