File: install.t

package info (click to toggle)
libfunction-parameters-perl 2.002005-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 624 kB
  • sloc: perl: 3,945; makefile: 3
file content (83 lines) | stat: -rw-r--r-- 1,906 bytes parent folder | download | duplicates (3)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!perl
use strict;
use warnings FATAL => 'all';

use Test::More tests => 22;

use constant MODIFIERS => qw(
    before after around augment override
);

use Function::Parameters qw(:modifiers :std), {
    map +("${_}_c" => { defaults => $_, runtime => 0 }), MODIFIERS
};

is eval 'before () {}', undef;
like $@, qr/\bexpecting a function name\b/;

my $test_pkg;
{
    package NotMain;
    BEGIN { $test_pkg = __PACKAGE__; }

    my $TRACE;
    fun TRACE($str) {
        $TRACE .= " $str";
    }
    fun getT() {
        my $r = $TRACE;
        $TRACE = '';
        $r
    }

    BEGIN {
        for my $m (::MODIFIERS) {
            my $sym = do { no strict 'refs'; \*$m };
            *$sym = fun ($name, $body) {
                TRACE "$m($name)";
                $body->('A', 'B', 'C');
            };
        }
    }

    BEGIN { ::is getT, undef; }
    ::is getT, '';

    around_c k_1($x) {
        TRACE "k_1($orig, $self, $x | @_)";
    }
    around k_2($x) {
        TRACE "k_2($orig, $self, $x | @_)";
    }
    BEGIN { ::is getT, ' around(k_1) k_1(A, B, C | C)'; }
    ::is getT, ' around(k_2) k_2(A, B, C | C)';

    before_c k_3($x, $y) {
        TRACE "k_3($self, $x, $y | @_)";
    }
    before k_4($x, $y) {
        TRACE "k_4($self, $x, $y | @_)";
    }
    BEGIN { ::is getT, ' before(k_3) k_3(A, B, C | B C)'; }
    ::is getT, ' before(k_4) k_4(A, B, C | B C)';

    after_c k_5($x, $y) {
        TRACE "k_5($self, $x, $y | @_)";
    }
    after k_6($x, $y) {
        TRACE "k_6($self, $x, $y | @_)";
    }
    BEGIN { ::is getT, ' after(k_5) k_5(A, B, C | B C)'; }
    ::is getT, ' after(k_6) k_6(A, B, C | B C)';
}

BEGIN {
    for my $i (1 .. 6) {
        my $m = "k_$i";
        is $test_pkg->can($m), undef, "$test_pkg->can($m) is undef at compile time";
    }
}
for my $i (1 .. 6) {
    my $m = "k_$i";
    is $test_pkg->can($m), undef, "$test_pkg->can($m) is undef at runtime";
}