add begin.t from Method::Signatures
[p5sagit/Function-Parameters.git] / t / method_runtime.t
CommitLineData
42e595b0 1#!perl
2use warnings FATAL => 'all';
3use strict;
4
5use Test::More tests => 29;
6
7use Function::Parameters {
8 fun => 'function_strict',
9 method => { defaults => 'method_strict', runtime => 1 },
10};
11
12{
13 package Foo;
14
15 ::ok !defined &f1;
16 method f1() {}
17 ::ok defined &f1;
18
19 ::ok !defined &f2;
20 ::ok !defined &Bar::f2;
21 method Bar::f2() {}
22 ::ok !defined &f2;
23 ::ok defined &Bar::f2;
24
25 ::ok !defined &f3;
26 if (@ARGV < 0) { method f3() {} }
27 ::ok !defined &f3;
28}
29
30fun g1() { (caller 0)[3] }
31method g2() { (caller 0)[3] }
32fun Bar::g1() { (caller 0)[3] }
33method Bar::g2() { (caller 0)[3] }
34
35is g1, 'main::g1';
36is 'main'->g2, 'main::g2';
37is Bar::g1, 'Bar::g1';
38is 'Bar'->g2, 'Bar::g2';
39
40use Function::Parameters { fun_r => { defaults => 'function_strict', runtime => 1 } };
41
42{
43 package Foo_r;
44
45 ::ok !defined &f1;
46 fun_r f1() {}
47 ::ok defined &f1;
48
49 ::ok !defined &f2;
50 ::ok !defined &Bar_r::f2;
51 fun_r Bar_r::f2() {}
52 ::ok !defined &f2;
53 ::ok defined &Bar_r::f2;
54
55 ::ok !defined &f3;
56 if (@ARGV < 0) { fun_r f3() {} }
57 ::ok !defined &f3;
58}
59
60fun h1() { (caller 0)[3] }
61fun_r h2() { (caller 0)[3] }
62fun Bar::h1() { (caller 0)[3] }
63fun_r Bar::h2() { (caller 0)[3] }
64
65is h1, 'main::h1';
66is h2(), 'main::h2';
67is Bar::h1, 'Bar::h1';
68is Bar::h2(), 'Bar::h2';
69
70fun_r p1($x, $y) :($$) {}
71is prototype(\&p1), '$$';
72is prototype('p1'), '$$';
73is prototype('main::p1'), '$$';
74
75fun_r Bar::p2($x, $y = 0) :($;$) {}
76is prototype(\&Bar::p2), '$;$';
77is prototype('Bar::p2'), '$;$';