Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 123243
Status: rejected
Priority: 0/
Queue: Type-Tiny

People
Owner: Nobody in particular
Requestors: JIRA [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: Code from Type::Utils synopsis doesn't work
Hello,

the coersion as given in the Type::Utils synopsis doesn't work.
Even when I copy the code verbatim and then use it like given below, it won't work.:

 package Test;

 use Moo;

 use MT qw/AllCaps/;

  has 'attr' => (
    is  => 'rw',
    isa => AllCaps
  );
 
  package main;
 
  use Modern::Perl '2017';
 
 my $t = Test->new(attr => 'aa');
On Wed Oct 11 04:14:04 2017, JIRA wrote: Show quoted text
> Hello, > > the coersion as given in the Type::Utils synopsis doesn't work. > Even when I copy the code verbatim and then use it like given below, > it won't > work.: > > package Test; > > use Moo; > > use MT qw/AllCaps/; > > has 'attr' => ( > is => 'rw', > isa => AllCaps > ); > > package main; > > use Modern::Perl '2017'; > > my $t = Test->new(attr => 'aa');
You aren't using the type properly with Moo to do what you want. You also need to pass in the coerce => 1 option when creating the attribute. The synopsis of Type::Utils only covers creating the type, and is accurate.
Dne 2017-10-13 05:17:04, haarg napsal(a):
Show quoted text
> On Wed Oct 11 04:14:04 2017, JIRA wrote:
> > Hello,
> >
> > the coersion as given in the Type::Utils synopsis doesn't work.
> > Even when I copy the code verbatim and then use it like given below,
> > it won't
> > work.:
> >
> > package Test;
> >
> > use Moo;
> >
> > use MT qw/AllCaps/;
> >
> > has 'attr' => (
> > is => 'rw',
> > isa => AllCaps
> > );
> >
> > package main;
> >
> > use Modern::Perl '2017';
> >
> > my $t = Test->new(attr => 'aa');
>
> You aren't using the type properly with Moo to do what you want. You
> also need to pass in the coerce => 1 option when creating the
> attribute.
>
> The synopsis of Type::Utils only covers creating the type, and is
> accurate.


Yes, I was missing the "coersion => 1". Sorry. With it it works.
I was trying to make my type definitions by following the synopsis and could not make it work. There I used the coerce attribute however, but now I understand I had the "where" part wrong.

Thank you