API-MailboxOrg

 view release on metacpan or  search on metacpan

lib/API/MailboxOrg/Types.pm  view on Meta::CPAN

        use Moo;
        use API::MailboxOrg::Types qw(Boolean HashRefRestricted);

        has true_or_false => ( is => 'ro', isa => Boolean, coerce => 1 );
        has map           => ( is => 'ro', isa => HashRefRestricted[qw(a b)] ); # allow only keys a and b

        1;
    }

    my $obj = TestClass->new(
        true_or_false => 1,  # 0|1|""|undef|JSON::PP::Boolean object
        map  => {
            a => 1,
            b => 1,
            # a key 'c' would cause a 'die'
        },
    );

=head1 TYPES

=head2 HashRefRestricted[`a]

lib/API/MailboxOrg/Types.pm  view on Meta::CPAN

=head1 COERCIONS

These coercions are defined.

=head2 To Boolean

=over 4

=item * String/Integer to boolean

The values "" (empty string), I<undef>, 0, and 1 are coerced to C<JSON::PP::Boolean> objects.

=back

=head1 AUTHOR

Renee Baecker <reneeb@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2022 by Renee Baecker.

t/types/002_boolean.t  view on Meta::CPAN

        my $obj = TestClass->new;

        lives_ok {
            $obj->true_or_false( 1 );
        };

        is $obj->true_or_false, 1;
        isa_ok $obj->true_or_false, 'JSON::PP::Boolean';
    };

    it 'allows undef' => sub {
        my $obj = TestClass->new;

        lives_ok {
            $obj->true_or_false( undef );
        };

        is $obj->true_or_false, 0;
        isa_ok $obj->true_or_false, 'JSON::PP::Boolean';
    };

    it 'allows empty string' => sub {
        my $obj = TestClass->new;

        lives_ok {



( run in 1.027 second using v1.01-cache-2.11-cpan-d80b1682f3f )