#!/usr/bin/perl use warnings; use strict; use Cpanel::JSON::XS; { package My::Package; use Moose; has attr => ( is => 'ro', isa => 'Bool' ); __PACKAGE__->meta->make_immutable; } my $obj = 'My::Package'->new(attr => Cpanel::JSON::XS::true()); #### Attribute (attr) does not pass the type constraint because: Validation failed for 'Bool' with value JSON::PP::Boolean=SCALAR(0x1dc1558) at constructor My::Package::new (defined at 1.pl line 15) line 31 #### subtype 'Bool' => as 'Item' => where { !defined($_) || $_ eq "" || "$_" eq '1' || "$_" eq '0' } => inline_as { '(' . '!defined(' . $_[1] . ') ' . '|| ' . $_[1] . ' eq "" ' . '|| (' . $_[1] . '."") eq "1" ' . '|| (' . $_[1] . '."") eq "0"' . ')' }; #### &overload::import( 'overload', # workaround 5.6 reserved keyword warning "0+" => sub { ${$_[0]} }, "++" => sub { $_[0] = ${$_[0]} + 1 }, "--" => sub { $_[0] = ${$_[0]} - 1 }, '""' => sub { ${$_[0]} == 1 ? 'true' : '0' }, # GH 29 'eq' => sub { my ($obj, $op) = ref ($_[0]) ? ($_[0], $_[1]) : ($_[1], $_[0]); if ($op eq 'true' or $op eq 'false') { return "$obj" eq 'true' ? 'true' eq $op : 'false' eq $op; } else { return $obj ? 1 == $op : 0 == $op; } }, fallback => 1); #### Cpanel::JSON::XS::true() eq '1'; #### { use Moose::Util::TypeConstraints; my $class = ref Cpanel::JSON::XS::true(); class_type($class); coerce Bool => from $class => via { !! $_ }; } #... has attr => ( is => 'ro', isa => 'Bool', coerce => 1 ); #### ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,