Update test style
[gitmo/MooseX-Params-Validate.git] / t / 010.overloaded.t
1 use Test::More tests => 4;
2 use strict;
3 use warnings;
4
5 {
6     package Foo;
7
8     use Moose;
9     use MooseX::Params::Validate;
10     use overload (
11         qw{""} => 'to_string',
12     );
13
14     has 'id' => (
15         is      => 'ro',
16         isa     => 'Str',
17         default => '1.10.100',
18     );
19
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 }
40
41 isa_ok( my $foo = Foo->new(), 'Foo', 'new' );
42
43 is( $foo->id, '1.10.100', 'id' );
44
45 is( $foo->to_string, '1.10.100', 'to_string' );
46
47 is(
48     $foo->to_string( padded => 1 ), '0001.0010.0100',
49     'to_string( padded => 1 )'
50 );
51