summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorToby Inkster <mail@tobyinkster.co.uk>2013-06-28 13:51:05 +0100
committerToby Inkster <mail@tobyinkster.co.uk>2013-06-28 13:51:05 +0100
commit58289007ae7ec4117af6db09e4875945ff458707 (patch)
tree9d05c290c012289a916578887d4f681f54cf8dac /t
parent4000c953cea9a70df68572698788239ba3c0dffd (diff)
MooX::HandlesVia support
Diffstat (limited to 't')
-rw-r--r--t/06handlesvia.t84
1 files changed, 84 insertions, 0 deletions
diff --git a/t/06handlesvia.t b/t/06handlesvia.t
new file mode 100644
index 0000000..cc13686
--- /dev/null
+++ b/t/06handlesvia.t
@@ -0,0 +1,84 @@
+=head1 PURPOSE
+
+See if L<MooX::HandlesVia> support works.
+
+=head1 AUTHOR
+
+Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
+
+=head1 COPYRIGHT AND LICENCE
+
+This software is copyright (c) 2013 by Toby Inkster.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
+
+=cut
+
+use strict;
+use warnings;
+use Test::More;
+
+use Test::Requires "MooX::HandlesVia";
+
+{
+ package Local::ThingyContainer;
+ use Moo;
+ use MooX::late;
+
+ has _thingies => (
+ traits => ['Array'],
+ is => 'ro',
+ isa => 'ArrayRef[Str]',
+ default => sub { [] },
+ handles => {
+ all => 'elements',
+ add => 'push',
+ count => 'count',
+ },
+ );
+}
+
+{
+ package Local::Foo;
+ use Moo;
+ use MooX::late;
+
+ has code => (
+ traits => ['Code'],
+ is => 'ro',
+ isa => 'CodeRef',
+ handles => {
+ e => 'execute',
+ em => 'execute_method',
+ },
+ );
+}
+
+my $c = 'Local::ThingyContainer'->new;
+
+is($c->count, 0);
+
+$c->add(qw/ Foo Bar Baz /);
+$c->add(qw/ Quux /);
+
+is($c->count, 4);
+
+is_deeply(
+ [ $c->all ],
+ [qw/ Foo Bar Baz Quux /],
+);
+
+my $x = 'Local::Foo'->new(code => sub { [@_] });
+
+is_deeply(
+ $x->e(1..3),
+ [1..3],
+);
+
+is_deeply(
+ $x->em(1..3),
+ [$x, 1..3],
+);
+
+done_testing;