|
Packit |
9002b2 |
use strict;
|
|
Packit |
9002b2 |
use warnings;
|
|
Packit |
9002b2 |
|
|
Packit |
9002b2 |
use Test::More;
|
|
Packit |
9002b2 |
|
|
Packit |
9002b2 |
use DateTime::Format::Builder::Parser;
|
|
Packit |
9002b2 |
|
|
Packit |
9002b2 |
{
|
|
Packit |
9002b2 |
my $new_sub = sub {
|
|
Packit |
9002b2 |
my $x = shift;
|
|
Packit |
9002b2 |
sub { $_[1] . $x }
|
|
Packit |
9002b2 |
};
|
|
Packit |
9002b2 |
my @cbs = ( map { $new_sub->($_) } qw( a b c d e f g ) );
|
|
Packit |
9002b2 |
my $cb = DateTime::Format::Builder::Parser->merge_callbacks(@cbs);
|
|
Packit |
9002b2 |
is( $cb->( input => "x" ) => "xabcdefg", "Callback chaining works." );
|
|
Packit |
9002b2 |
|
|
Packit |
9002b2 |
my $cbr = DateTime::Format::Builder::Parser->merge_callbacks( \@cbs );
|
|
Packit |
9002b2 |
is(
|
|
Packit |
9002b2 |
$cbr->( input => "x" ) => "xabcdefg",
|
|
Packit |
9002b2 |
"Callback chaining works on ref."
|
|
Packit |
9002b2 |
);
|
|
Packit |
9002b2 |
}
|
|
Packit |
9002b2 |
|
|
Packit |
9002b2 |
{
|
|
Packit |
9002b2 |
my $inout = sub { $_[0] . "foo" };
|
|
Packit |
9002b2 |
my $cb = DateTime::Format::Builder::Parser->merge_callbacks($inout);
|
|
Packit |
9002b2 |
is( $cb->("foo") => "foofoo", "Single callback works." );
|
|
Packit |
9002b2 |
}
|
|
Packit |
9002b2 |
|
|
Packit |
9002b2 |
{
|
|
Packit |
9002b2 |
my $empty = DateTime::Format::Builder::Parser->merge_callbacks(undef);
|
|
Packit |
9002b2 |
ok( !defined $empty, "Given undef, do bugger all." );
|
|
Packit |
9002b2 |
|
|
Packit |
9002b2 |
$empty = DateTime::Format::Builder::Parser->merge_callbacks();
|
|
Packit |
9002b2 |
ok( !defined $empty, "Given nothing, do bugger all." );
|
|
Packit |
9002b2 |
|
|
Packit |
9002b2 |
$empty = DateTime::Format::Builder::Parser->merge_callbacks( [] );
|
|
Packit |
9002b2 |
ok( !defined $empty, "Given empty arrayref, do bugger all." );
|
|
Packit |
9002b2 |
}
|
|
Packit |
9002b2 |
|
|
Packit |
9002b2 |
{
|
|
Packit |
9002b2 |
my $error = eval {
|
|
Packit |
9002b2 |
DateTime::Format::Builder::Parser->merge_callbacks( { foo => 4 } );
|
|
Packit |
9002b2 |
};
|
|
Packit |
9002b2 |
ok( $@, "Correctly faulted on bad arguments." );
|
|
Packit |
9002b2 |
}
|
|
Packit |
9002b2 |
|
|
Packit |
9002b2 |
done_testing();
|