File: iso_date_example.t

package info (click to toggle)
libmethod-signatures-perl 20170211-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 672 kB
  • sloc: perl: 3,860; makefile: 2
file content (32 lines) | stat: -r--r--r-- 542 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl -w

package Foo;

use Test::More;
use Test::Exception;

use lib 't/lib';
use GenErrorRegex qw< required_error >;

use Method::Signatures;

method new($class:@_) {
    bless {@_}, $class;
}

method iso_date(
    :$year!,    :$month = 1, :$day = 1,
    :$hour = 0, :$min   = 0, :$sec = 0
)
{
    return "$year-$month-$day $hour:$min:$sec";
}

$obj = Foo->new;

is( $obj->iso_date(year => 2008), "2008-1-1 0:0:0" );
#line 25
throws_ok { $obj->iso_date() } required_error($obj, '$year', 'iso_date', LINE => 25);


done_testing();