]> git.vpit.fr Git - perl/modules/Lexical-Types.git/blobdiff - samples/basic.pl
A new synopsis
[perl/modules/Lexical-Types.git] / samples / basic.pl
index e35d8526f1c55b299e245c5df65b42cc3ba8a33b..9e38f1306f4a175013496775d84c8d620c39d21d 100644 (file)
@@ -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;