#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 26;
+use Test::More;
use Test::Exception;
+my $before = 0;
do {
package Person;
+ use Mouse;
- sub new {
- my $class = shift;
- my %args = @_;
-
- bless \%args, $class;
- }
-
- sub name { $_[0]->{name} = $_[1] if @_ > 1; $_[0]->{name} }
- sub age { $_[0]->{age} = $_[1] if @_ > 1; $_[0]->{age} }
+ has name => (is => 'rw');
+ has age => (is => 'rw');
sub make_string {
my($self, $template) = @_;
);
has me => (
- is => 'rw',
+ is => 'rw',
+ isa => 'Person',
default => sub { Person->new(age => 21, name => "Shawn") },
predicate => 'quid',
handles => [qw/name age/],
);
+
+ before me => sub { $before++ };
};
can_ok(Class => qw(person has_person person_name person_age name age quid));
ok($object->quid, "we have a Shawn");
is($object->name, "Shawn", "name handle");
is($object->age, 21, "age handle");
+is $before, 2, 'delegations with method modifiers';
is($object->me->name, "Shawn", "me->name");
is($object->me->age, 21, "me->age");
"correct handles layout for 'person'",
);
+throws_ok{
+ $object->person(undef);
+ $object->person_name();
+} qr/Cannot delegate person_name to name because the value of person is not defined/;
-{
- throws_ok{
- $object->person(undef);
- $object->person_name();
- } qr/Cannot delegate person_name to name because the value of person is not defined/;
-
- throws_ok{
- $object->person([]);
- $object->person_age();
- } qr/Cannot delegate person_age to age because the value of person is not an object/;
-}
+throws_ok{
+ $object->person([]);
+ $object->person_age();
+} qr/Cannot delegate person_age to age because the value of person is not an object/;
-eval{
+throws_ok{
$object->person(undef);
$object->person_name();
-};
-like $@, qr/Cannot delegate person_name to name because the value of person is not defined/;
+} qr/Cannot delegate person_name to name because the value of person is not defined/;
-eval{
+throws_ok{
$object->person([]);
$object->person_age();
-};
-like $@, qr/Cannot delegate person_age to age because the value of person is not an object/;
+} qr/Cannot delegate person_age to age because the value of person is not an object/;
+
+done_testing;