Fix small typo
[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}
37088308 33 ? join(
34 '.',
35 map { sprintf( "%04d", $_ ) } split( /\./, $self->id )
36 )
e79becc3 37 : $self->id;
38
39 return $id;
40 }
41}
d9d1529d 42
43isa_ok( my $foo = Foo->new(), 'Foo', 'new' );
44
45is( $foo->id, '1.10.100', 'id' );
46
47is( $foo->to_string, '1.10.100', 'to_string' );
48
e79becc3 49is(
50 $foo->to_string( padded => 1 ), '0001.0010.0100',
51 'to_string( padded => 1 )'
52);
d9d1529d 53
d7a80104 54done_testing();