Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/self/root/usr/share/doc/perl-Moose/t/attributes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/usr/share/doc/perl-Moose/t/attributes/accessor_override_method.t
use strict;
use warnings;
use Test::More;

use Test::Requires 'Test::Output';  # skip all if not installed

{

    package Foo;
    use Moose;

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

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_is(
    sub { $foo_meta->add_attribute( stub => ( is => 'rw' ) ) },
    q{},
    'overriding a stub with an accessor does not warn'
);
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;

Hry