File: begin.t

package info (click to toggle)
libmethod-signatures-perl 20170211-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 672 kB
  • sloc: perl: 3,860; makefile: 2
file content (74 lines) | stat: -r--r--r-- 1,552 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl

package Foo;

use strict;
use warnings;

use Test::More;
use Test::Exception;

use Method::Signatures;


our $phase;
BEGIN { $phase = 'compile-time' }
INIT  { $phase = 'run-time'     }


sub method_defined
{
    my ($method) = @_;

    local $Test::Builder::Level = $Test::Builder::Level + 1;
    lives_ok { Foo->$method } "method $method is defined at $phase";
}

sub method_undefined
{
    my ($method) = @_;

    local $Test::Builder::Level = $Test::Builder::Level + 1;
    throws_ok { Foo->$method } qr/Can't locate object method/, "method $method is undefined at $phase";
}


# The default configuration with compile at BEGIN on.
method top_level_default() {}

# Turn it off.
use Method::Signatures { compile_at_BEGIN => 0 };
method top_level_off() {}

# And on again.
use Method::Signatures { compile_at_BEGIN => 1 };
method top_level_on() {}

# Now turn it off inside a lexical scope
{
    use Method::Signatures { compile_at_BEGIN => 0 };
    method inner_scope_off() {}
}

# And it's restored.
method outer_scope_on() {}


# at compile-time, some should be defined and others shouldn't be
BEGIN {
    method_defined('top_level_default');
    method_undefined('top_level_off');
    method_defined('top_level_on');
    method_undefined('inner_scope_off');
    method_defined('outer_scope_on');
}

# by run-time, they should _all_ be defined
method_defined('top_level_default');
method_defined('top_level_off');
method_defined('top_level_on');
method_defined('inner_scope_off');
method_defined('outer_scope_on');


done_testing;