copied from svn
[gitmo/MooseX-Params-Validate.git] / t / 010.overloaded.t
CommitLineData
d9d1529d 1
2package Foo;
3use Moose;
4use MooseX::Params::Validate;
5use overload (
6 qw{""} => 'to_string',
7);
8
9has 'id' => ( is => 'ro', isa => 'Str', default => '1.10.100' );
10
11sub to_string {
12 my ($self, %args) = validated_hash( \@_,
13 padded => { isa => 'Bool', optional => 1, default => 0 },
14 );
15
16 # 1.10.100 => 0001.0010.0100
17 my $id = $args{ padded }
18 ? join( '.', map { sprintf( "%04d", $_ ) } split( /\./, $self->id ) )
19 : $self->id;
20
21 return $id;
22}
23
24package main;
25use Test::More tests => 4;
26use strict;
27use warnings;
28
29isa_ok( my $foo = Foo->new(), 'Foo', 'new' );
30
31is( $foo->id, '1.10.100', 'id' );
32
33is( $foo->to_string, '1.10.100', 'to_string' );
34
35is( $foo->to_string( padded => 1 ), '0001.0010.0100', 'to_string( padded => 1 )' );
36