[libtype-tiny-perl] 33/46: update documentation for Moo 1.006000

Jonas Smedegaard dr at jones.dk
Fri Sep 12 18:48:04 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 1.001_000
in repository libtype-tiny-perl.

commit f96bfd1a0f76ad6e1c2f34c0ad80018f1d65ea27
Author: Toby Inkster <mail at tobyinkster.co.uk>
Date:   Sun Sep 7 15:10:58 2014 +0100

    update documentation for Moo 1.006000
---
 lib/Type/Tiny/Manual/UsingWithMoo.pod | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/lib/Type/Tiny/Manual/UsingWithMoo.pod b/lib/Type/Tiny/Manual/UsingWithMoo.pod
index aa7f28a..c97649e 100644
--- a/lib/Type/Tiny/Manual/UsingWithMoo.pod
+++ b/lib/Type/Tiny/Manual/UsingWithMoo.pod
@@ -11,26 +11,23 @@ Type::Tiny::Manual::UsingWithMoo - how to use Type::Tiny and Type::Library with
    {
       package Person;
       
-      use Moo;
+      use Moo 1.006000;
+      use Sub::Quote qw( quote_sub );
       use Types::Standard qw( Str Int );
-      use Type::Utils qw( declare as where inline_as coerce from );
       
       has name => (
          is      => "ro",
          isa     => Str,
       );
       
-      my $PositiveInt = declare
-         as        Int,
-         where     {  $_ > 0  },
-         inline_as { "$_ =~ /^[0-9]+\$/ and $_ > 0" };
-      
-      coerce $PositiveInt, from Int, q{ abs $_ };
+      my $PositiveInt = Int
+         -> where( quote_sub '$_ > 0' )
+         -> plus_coercions( Int, sub { abs $_ } );
       
       has age => (
          is      => "rwp",
          isa     => $PositiveInt,
-         coerce  => $PositiveInt->coercion,
+         coerce  => 1,
       );
       
       sub get_older {
@@ -49,9 +46,19 @@ Type::Tiny overloads C<< &{} >>. Moo supports using objects that overload
 C<< &{} >> as C<isa> constraints, so Type::Tiny objects can directly be used
 in C<isa>.
 
-Moo doesn't support C<< coerce => 1 >> but requires a coderef as a coercion.
-However, again it supports using objects that overload C<< &{} >>, which
-Type::Coercion does, allowing C<< coerce => $Type->coercion >> to work.
+Moo prior to 1.006000 doesn't support C<< coerce => 1 >>, instead
+requiring a coderef to use as a coercion. However, Type::Tiny can
+provide you with a suitable coderef to use (actually an object that
+overloads C<< &{} >>). Just use:
+
+   has age => (
+      is      => "rwp",
+      isa     => $PositiveInt,
+      coerce  => $PositiveInt->coercion,
+   );
+
+If you can upgrade to the latest Moo, and use C<< coerce => 1 >> you'll
+have a lot more fun though. :-)
 
 Type::Tiny hooks into Moo's HandleMoose interface to ensure that type
 constraints get inflated to Moose type constraints if and when Moo inflates

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libtype-tiny-perl.git



More information about the Pkg-perl-cvs-commits mailing list