From: Vincent Pit Date: Sat, 7 Mar 2009 12:10:15 +0000 (+0100) Subject: Document the initializer method in its own section X-Git-Tag: v0.04~5 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLexical-Types.git;a=commitdiff_plain;h=cd8d951930816a806c3c5913fdea42dce49cc581 Document the initializer method in its own section --- 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.