File: 24_eval_in_modifiers.t

package info (click to toggle)
libdata-util-perl 0.67-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 556 kB
  • sloc: perl: 2,958; ansic: 416; makefile: 8
file content (48 lines) | stat: -rw-r--r-- 1,243 bytes parent folder | download | duplicates (5)
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
38
39
40
41
42
43
44
45
46
47
48
#!perl -w
# reported by nekoya
package Person;
use Data::Util qw/:all/;

{
    no warnings 'redefine';
    my $before = modify_subroutine(
        get_code_ref(__PACKAGE__, 'before_chk'),
        before => [ sub { eval "use Hoge" } ]
    );

    my $after = modify_subroutine(
        get_code_ref(__PACKAGE__, 'after_chk'),
        after => [ sub { eval "use Hoge" } ]
    );

    my $around = modify_subroutine(
        get_code_ref(__PACKAGE__, 'around_chk'),
        around => [ sub {
            my $orig = shift;
            my $self = shift;
            eval "use Hoge";
            $self->$orig(@_);
        } ]
    );

    install_subroutine(__PACKAGE__, 'before_chk' => $before);
    install_subroutine(__PACKAGE__, 'after_chk' => $after);
    install_subroutine(__PACKAGE__, 'around_chk' => $around);
}

sub new { bless {}, shift }

sub before_chk { 'before checked' }
sub after_chk { 'after checked' }
sub around_chk { 'around checked' }

package main;
use strict;
use warnings;
use Test::More tests => 4;

my $pp = Person->new;
is $pp->before_chk, 'before checked', 'before check done';
is $pp->after_chk, 'after checked', 'after check done';
is $pp->around_chk, 'around checked', 'around check done';
ok 1, 'all tests finished';