Tidy existing code
[gitmo/Moose.git] / t / attributes / accessor_override_method.t
CommitLineData
baf17065 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5
4d438a84 6use Test::Requires {
e0dc8e65 7 'Test::Output' => '0.01', # skip all if not installed
4d438a84 8};
baf17065 9
10{
e0dc8e65 11
baf17065 12 package Foo;
13 use Moose;
14
e0dc8e65 15 sub get_a { }
16 sub set_b { }
17 sub has_c { }
baf17065 18 sub clear_d { }
e0dc8e65 19 sub e { }
baf17065 20}
21
22my $foo_meta = Foo->meta;
e0dc8e65 23stderr_like(
24 sub { $foo_meta->add_attribute( a => ( reader => 'get_a' ) ) },
25 qr/^You are overwriting a locally defined method \(get_a\) with an accessor/,
26 'reader overriding gives proper warning'
27);
28stderr_like(
29 sub { $foo_meta->add_attribute( b => ( writer => 'set_b' ) ) },
30 qr/^You are overwriting a locally defined method \(set_b\) with an accessor/,
31 'writer overriding gives proper warning'
32);
33stderr_like(
34 sub { $foo_meta->add_attribute( c => ( predicate => 'has_c' ) ) },
35 qr/^You are overwriting a locally defined method \(has_c\) with an accessor/,
36 'predicate overriding gives proper warning'
37);
38stderr_like(
39 sub { $foo_meta->add_attribute( d => ( clearer => 'clear_d' ) ) },
40 qr/^You are overwriting a locally defined method \(clear_d\) with an accessor/,
41 'clearer overriding gives proper warning'
42);
43stderr_like(
44 sub { $foo_meta->add_attribute( e => ( is => 'rw' ) ) },
45 qr/^You are overwriting a locally defined method \(e\) with an accessor/,
46 'accessor overriding gives proper warning'
47);
48stderr_like(
49 sub { $foo_meta->add_attribute( has => ( is => 'rw' ) ) },
50 qr/^You are overwriting a locally defined function \(has\) with an accessor/,
51 'function overriding gives proper warning'
52);
3968746e 53
a28e50e4 54done_testing;