? ('LICENSE'=> 'perl')
: ()),
PL_FILES => {},
+ BUILD_REQUIRES => {
+ 'Dir::Self' => 0,
+ },
PREREQ_PM => {
'Test::More' => 0,
'warnings' => 0,
'strict' => 0,
'Devel::Declare' => 0,
'B::Hooks::EndOfScope' => 0,
- 'B::Compiling' => 0,
+ 'Carp' => 0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Function-Parameters-*' },
(
$x
)
- :
+ : #hello
(
$
)
- {
+ {@_ == 1 or return;
$x
}
fun id_3 ##
( $x ##
- ) ##
+ ) ##AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
{ ##
$x ##
} ##
--- /dev/null
+#!perl
+
+use Test::More tests => 10;
+
+use warnings FATAL => 'all';
+use strict;
+
+use Function::Parameters;
+
+method id_1() { $self }
+
+method id_2
+ (
+
+ )
+ : #hello
+ (
+ $
+ )
+ {@_ == 0 or return;
+ $self
+ }
+
+method##
+ id_3 ##
+ ( ##
+ #
+ ) ##AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ { ##
+ ##
+ } ##
+
+method add($y) {
+ $self + $y
+}
+
+method mymap(@args) :(&@) {
+ my @res;
+ for (@args) {
+ push @res, $self->($_);
+ }
+ @res
+}
+
+method fac_1() {
+ $self < 2 ? 1 : $self * fac_1 $self - 1
+}
+
+method fac_2() :($) {
+ $self < 2 ? 1 : $self * fac_2 $self - 1
+}
+
+ok id_1 1;
+ok id_1(1), 'basic sanity';
+ok id_2 1, 'simple prototype';
+ok id_3(1), 'definition over multiple lines';
+is add(2, 2), 4, '2 + 2 = 4';
+is add(39, 3), 42, '39 + 3 = 42';
+is_deeply [mymap { $_ * 2 } 2, 3, 5, 9], [4, 6, 10, 18], 'mymap works';
+is fac_1(5), 120, 'fac_1';
+is fac_2 6, 720, 'fac_2';
+is method ($y) { $self . $y }->(method () { $self + 1 }->(3), method () { $self * 2 }->(1)), '42', 'anonyfun';
--- /dev/null
+use strict;
+use Function::Parameters;
+
+fun get_record( $agent, $target_name ) {
+ for my $record ( @$records ) {
+ }
+}
+
+fun get_ip( $agent ) {
+}
+
--- /dev/null
+#!perl
+
+use Test::More tests => 2;
+
+use warnings FATAL => 'all';
+use strict;
+
+use Dir::Self;
+
+#use Test::Fatal;
+
+my $file = __DIR__ . "/eating_strict_error.fail";
+my $done = do $file;
+my $exc = $@;
+my $err = $!;
+
+is $done, undef, "faulty code doesn't load";
+is $exc, qq{Global symbol "\$records" requires explicit package name at $file line 5.\nBEGIN not safe after errors--compilation aborted at $file line 9.\n};
+$exc or die "$file: $err";
is $add->(2, 4), 6;
-ok !eval { Function::Parameters->import('g', 'h'); 1 };
-like $@, qr/ is not exported /;
+ok !eval { Function::Parameters->import('g', 'h', 'i'); 1 };
for my $kw ('', '42', 'A::B', 'a b') {
ok !eval{ Function::Parameters->import($kw); 1 };
like $@, qr/valid identifier /;
}
+use Function::Parameters 'func_a', 'meth_a';
+
+func_a cat_a($x, $y) {
+ $x . $y
+}
+
+meth_a tac_a($x) {
+ $x . $self
+}
+
+is cat_a('ab', 'cde'), 'abcde';
+is tac_a('ab', 'cde'), 'cdeab';
+
+use Function::Parameters {
+ meth_b => 'method',
+ func_b => 'function',
+};
+
+func_b cat_b($x, $y) {
+ $x . $y
+}
+
+meth_b tac_b($x) {
+ $x . $self
+}
+
+is cat_b('ab', 'cde'), 'abcde';
+is tac_b('ab', 'cde'), 'cdeab';
+
done_testing;