]> git.proxmox.com Git - perlmod.git/blame - test.pl
add instantiate_magic convenience macro
[perlmod.git] / test.pl
CommitLineData
e95a2c0a
WB
1#!/usr/bin/env perl
2
3use v5.28.0;
4
5use lib '.';
6use RSPM::Bless;
61143f5d 7use RSPM::Foo142;
93eaead2 8use RSPM::Option;
e95a2c0a 9
0864428b
WB
10STDOUT->autoflush;
11
e95a2c0a
WB
12my $v = RSPM::Bless->new("Hello");
13$v->something();
245de6dd 14$v->something_nonraw();
e95a2c0a
WB
15my ($a, $b, $c) = $v->multi_return();
16say "Got ($a, $b, $c)";
17my @ret = $v->multi_return();
18say "Got: ".scalar(@ret)." values: @ret";
19
20$v->another(54);
61143f5d
WB
21
22my $param = { a => 1 };
23my $s = "Hello You";
b5c53f3d 24print "These should be called with a valid substr:\n";
61143f5d
WB
25RSPM::Foo142::test(substr($s, 3, 3));
26RSPM::Foo142::teststr(substr($s, 3, 3));
b5c53f3d 27print "Parameter exists: " . (exists($param->{x}) ? "YES" : "NO") . "\n";
61143f5d 28RSPM::Foo142::test($param->{x});
b5c53f3d 29print "Was auto-vivified: " . (exists($param->{x}) ? "YES" : "NO") . "\n";
61143f5d 30RSPM::Foo142::teststr($param->{x});
fa780264 31
83ac604e
WB
32my $a = "Can I have some coffee please?\n";
33print $a;
34my $b = RSPM::Foo142::test_serde($a);
35print $b;
36my $c = RSPM::Foo142::test_serde($b);
37print $c;
38
39use utf8;
40binmode STDOUT, ':utf8';
41my $a = "Can I have some ☕ please?\n";
42print $a;
43my $b = RSPM::Foo142::test_serde($a);
44print $b;
45my $c = RSPM::Foo142::test_serde($b);
46print $c;
93eaead2
FE
47
48sub to_string {
49 my ($param) = @_;
50
51 my $state = $param->{tristate};
52 $state = int($state) if defined($state);
53
54 my $a;
55 if (defined($state)) {
56 $a = $state ? "Some(true)" : "Some(false)";
57 } else {
58 $a = "None";
59 }
60
61 my $b = RSPM::Option::to_string($state);
62 my $c = RSPM::Option::struct_to_string({ 'tristate' => $state });
63
64 print "$a\n";
65 print "$b\n";
66 print "$c\n";
67}
68
69to_string({ 'tristate' => '0' });
70to_string({ 'tristate' => '1' });
71to_string({ 'tristate' => undef });
6ccbcbec
WB
72
73my $ref1 = { x => "x was stored" };
74my $ref2 = RSPM::Foo142::test_refs({ copied => "copied string", reference => $ref1 });
75print($ref1->{x}, "\n");
76$ref2->{x} = "x was changed";
77print($ref1->{x}, "\n");