Use done_testing (require Test::More 0.88)
[gitmo/MooseX-Params-Validate.git] / t / 010_overloaded.t
CommitLineData
d7a80104 1use Test::More;
e79becc3 2use strict;
3use warnings;
d9d1529d 4
e79becc3 5{
6 package Foo;
d9d1529d 7
e79becc3 8 use Moose;
9 use MooseX::Params::Validate;
10 use overload (
11 qw{""} => 'to_string',
12 );
d9d1529d 13
e79becc3 14 has 'id' => (
15 is => 'ro',
16 isa => 'Str',
17 default => '1.10.100',
d9d1529d 18 );
d9d1529d 19
e79becc3 20 sub to_string {
21 my ( $self, %args ) = validated_hash(
22 \@_,
23 padded => {
24 isa => 'Bool',
25 optional => 1,
26 default => 0,
27 },
28 );
29
30 # 1.10.100 => 0001.0010.0100
31 my $id
32 = $args{padded}
33 ? join( '.',
34 map { sprintf( "%04d", $_ ) } split( /\./, $self->id ) )
35 : $self->id;
36
37 return $id;
38 }
39}
d9d1529d 40
41isa_ok( my $foo = Foo->new(), 'Foo', 'new' );
42
43is( $foo->id, '1.10.100', 'id' );
44
45is( $foo->to_string, '1.10.100', 'to_string' );
46
e79becc3 47is(
48 $foo->to_string( padded => 1 ), '0001.0010.0100',
49 'to_string( padded => 1 )'
50);
d9d1529d 51
d7a80104 52done_testing();