From: Vincent Pit Date: Thu, 5 Mar 2009 21:01:46 +0000 (+0100) Subject: A new synopsis X-Git-Tag: v0.03~3 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLexical-Types.git;a=commitdiff_plain;h=d7bc605f5faa98d26edda28996af1377d5ec1bcf A new synopsis --- diff --git a/lib/Lexical/Types.pm b/lib/Lexical/Types.pm index 85df039..b22c2cc 100644 --- a/lib/Lexical/Types.pm +++ b/lib/Lexical/Types.pm @@ -24,15 +24,29 @@ BEGIN { =head1 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 =head1 DESCRIPTION diff --git a/samples/basic.pl b/samples/basic.pl index e35d852..9e38f13 100644 --- a/samples/basic.pl +++ b/samples/basic.pl @@ -3,14 +3,30 @@ use strict; use warnings; +use blib; + +{ 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 +print ref($x), "\n"; # My::Types::Str; + { - package Str; + package My::Types::Int; - sub TYPEDSCALAR { $_[1] = ' ' x 10 } + sub TYPEDSCALAR { bless { }, shift } } use Lexical::Types; -my Str $x; +use constant Int => 'My::Types::Int'; -print length($x), "\n"; # 10 +my Int $y; # $y is now a My::Types::Int object +print ref($y), "\n"; # My::Types::Int;