File: 027_accessor_override_method.t

package info (click to toggle)
libmoose-perl 1.09-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,004 kB
  • ctags: 1,472
  • sloc: perl: 25,387; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,571 bytes parent folder | download
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
33
34
35
36
37
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;

BEGIN {
    eval "use Test::Output;";
    plan skip_all => "Test::Output is required for this test" if $@;
}

{
    package Foo;
    use Moose;

    sub get_a { }
    sub set_b { }
    sub has_c { }
    sub clear_d { }
    sub e { }
}

my $foo_meta = Foo->meta;
stderr_like(sub { $foo_meta->add_attribute(a => (reader => 'get_a')) },
            qr/^You are overwriting a locally defined method \(get_a\) with an accessor/, 'reader overriding gives proper warning');
stderr_like(sub { $foo_meta->add_attribute(b => (writer => 'set_b')) },
            qr/^You are overwriting a locally defined method \(set_b\) with an accessor/, 'writer overriding gives proper warning');
stderr_like(sub { $foo_meta->add_attribute(c => (predicate => 'has_c')) },
            qr/^You are overwriting a locally defined method \(has_c\) with an accessor/, 'predicate overriding gives proper warning');
stderr_like(sub { $foo_meta->add_attribute(d => (clearer => 'clear_d')) },
            qr/^You are overwriting a locally defined method \(clear_d\) with an accessor/, 'clearer overriding gives proper warning');
stderr_like(sub { $foo_meta->add_attribute(e => (is => 'rw')) },
            qr/^You are overwriting a locally defined method \(e\) with an accessor/, 'accessor overriding gives proper warning');

stderr_like(sub { $foo_meta->add_attribute(has => (is => 'rw')) },
            qr/^You are overwriting a locally defined function \(has\) with an accessor/, 'function overriding gives proper warning');

done_testing;