From: Vincent Pit Date: Thu, 22 Jul 2010 19:45:37 +0000 (+0200) Subject: Enforce the non-negativity of some attributes with anonymous types X-Git-Tag: v0.01~10 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=d819d3e4b5357f615a15c6c68c28b0612036ece8;p=perl%2Fmodules%2FLaTeX-TikZ.git Enforce the non-negativity of some attributes with anonymous types --- diff --git a/lib/LaTeX/TikZ/Mod/Pattern/Dots.pm b/lib/LaTeX/TikZ/Mod/Pattern/Dots.pm index b029915..45714b1 100644 --- a/lib/LaTeX/TikZ/Mod/Pattern/Dots.pm +++ b/lib/LaTeX/TikZ/Mod/Pattern/Dots.pm @@ -18,18 +18,19 @@ our $VERSION = '0.01'; use Sub::Name (); use Any::Moose; +use Any::Moose 'Util::TypeConstraints'; extends 'LaTeX::TikZ::Mod::Pattern'; has 'dot_width' => ( is => 'ro', - isa => 'Int', + isa => subtype('Num' => where { LaTeX::TikZ::Tools::numcmp($_, 0) >= 0 }), default => 1, ); has 'space_width' => ( is => 'ro', - isa => 'Int', + isa => subtype('Num' => where { LaTeX::TikZ::Tools::numcmp($_, 0) >= 0 }), default => 1, ); diff --git a/lib/LaTeX/TikZ/Mod/Pattern/Lines.pm b/lib/LaTeX/TikZ/Mod/Pattern/Lines.pm index d38222c..a868440 100644 --- a/lib/LaTeX/TikZ/Mod/Pattern/Lines.pm +++ b/lib/LaTeX/TikZ/Mod/Pattern/Lines.pm @@ -36,13 +36,13 @@ has 'direction' => ( has 'line_width' => ( is => 'ro', - isa => 'Int', + isa => subtype('Num' => where { LaTeX::TikZ::Tools::numcmp($_, 0) >= 0 }), default => 1, ); has 'space_width' => ( is => 'ro', - isa => 'Int', + isa => subtype('Num' => where { LaTeX::TikZ::Tools::numcmp($_, 0) >= 0 }), default => 1, ); diff --git a/lib/LaTeX/TikZ/Set/Circle.pm b/lib/LaTeX/TikZ/Set/Circle.pm index 06a692a..8efdd98 100644 --- a/lib/LaTeX/TikZ/Set/Circle.pm +++ b/lib/LaTeX/TikZ/Set/Circle.pm @@ -34,14 +34,9 @@ has 'center' => ( coerce => 1, ); -subtype 'LaTeX::TikZ::Set::Circle::Radius' - => as 'Num' - => where { LaTeX::TikZ::Tools::numcmp($_, 0) >= 1 } - => message { "$_ isn't a non-negative real number" }; - has 'radius' => ( is => 'ro', - isa => 'LaTeX::TikZ::Set::Circle::Radius', + isa => subtype('Num' => where { LaTeX::TikZ::Tools::numcmp($_, 0) > 0 }), required => 1, ); diff --git a/t/12-geo.t b/t/12-geo.t index 7ce5d64..f36d002 100644 --- a/t/12-geo.t +++ b/t/12-geo.t @@ -206,7 +206,7 @@ RES eval { Tikz->circle($o => -1); }; -like $@, qr/isn't a non-negative real number/, +like $@, failed_valid('__ANON__'), 'creating a circle with a negative radius croaks'; # Arc