Rechercher une page de manuel
MouseX::Types.3pm
Langue: en
Version: 2008-12-20 (ubuntu - 07/07/09)
Section: 3 (Bibliothèques de fonctions)
Sommaire
NAME
MouseX::Types - Organise your Mouse types in librariesSYNOPSIS
Library Definition
package MyLibrary; # predeclare our own types use MouseX::Types -declare => [qw( PositiveInt NegativeInt )]; # import builtin types use MouseX::Types::Mouse 'Int'; # type definition. subtype PositiveInt, as Int, where { $_ > 0 }, message { "Int is not larger than 0" }; subtype NegativeInt, as Int, where { $_ < 0 }, message { "Int is not smaller than 0" }; # type coercion coerce PositiveInt, from Int, via { 1 }; 1;
Usage
package Foo; use Mouse; use MyLibrary qw( PositiveInt NegativeInt ); # use the exported constants as type names has 'bar', isa => PositiveInt, is => 'rw'; has 'baz', isa => NegativeInt, is => 'rw'; sub quux { my ($self, $value); # test the value print "positive\n" if is_PositiveInt($value); print "negative\n" if is_NegativeInt($value); # coerce the value, NegativeInt doesn't have a coercion # helper, since it didn't define any coercions. $value = to_PositiveInt($value) or die "Cannot coerce"; } 1;
Contenus ©2006-2024 Benjamin Poulain
Design ©2006-2024 Maxime Vantorre