]> git.proxmox.com Git - perlmod.git/blame - test.pl
add is_defined helper glue
[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
WB
9
10my $v = RSPM::Bless->new("Hello");
11$v->something();
12my ($a, $b, $c) = $v->multi_return();
13say "Got ($a, $b, $c)";
14my @ret = $v->multi_return();
15say "Got: ".scalar(@ret)." values: @ret";
16
17$v->another(54);
61143f5d
WB
18
19my $param = { a => 1 };
20my $s = "Hello You";
b5c53f3d 21print "These should be called with a valid substr:\n";
61143f5d
WB
22RSPM::Foo142::test(substr($s, 3, 3));
23RSPM::Foo142::teststr(substr($s, 3, 3));
b5c53f3d 24print "Parameter exists: " . (exists($param->{x}) ? "YES" : "NO") . "\n";
61143f5d 25RSPM::Foo142::test($param->{x});
b5c53f3d 26print "Was auto-vivified: " . (exists($param->{x}) ? "YES" : "NO") . "\n";
61143f5d 27RSPM::Foo142::teststr($param->{x});
fa780264 28
83ac604e
WB
29my $a = "Can I have some coffee please?\n";
30print $a;
31my $b = RSPM::Foo142::test_serde($a);
32print $b;
33my $c = RSPM::Foo142::test_serde($b);
34print $c;
35
36use utf8;
37binmode STDOUT, ':utf8';
38my $a = "Can I have some ☕ please?\n";
39print $a;
40my $b = RSPM::Foo142::test_serde($a);
41print $b;
42my $c = RSPM::Foo142::test_serde($b);
43print $c;
93eaead2
FE
44
45sub to_string {
46 my ($param) = @_;
47
48 my $state = $param->{tristate};
49 $state = int($state) if defined($state);
50
51 my $a;
52 if (defined($state)) {
53 $a = $state ? "Some(true)" : "Some(false)";
54 } else {
55 $a = "None";
56 }
57
58 my $b = RSPM::Option::to_string($state);
59 my $c = RSPM::Option::struct_to_string({ 'tristate' => $state });
60
61 print "$a\n";
62 print "$b\n";
63 print "$c\n";
64}
65
66to_string({ 'tristate' => '0' });
67to_string({ 'tristate' => '1' });
68to_string({ 'tristate' => undef });