]> git.proxmox.com Git - perlmod.git/blob - test.pl
add is_defined helper glue
[perlmod.git] / test.pl
1 #!/usr/bin/env perl
2
3 use v5.28.0;
4
5 use lib '.';
6 use RSPM::Bless;
7 use RSPM::Foo142;
8 use RSPM::Option;
9
10 my $v = RSPM::Bless->new("Hello");
11 $v->something();
12 my ($a, $b, $c) = $v->multi_return();
13 say "Got ($a, $b, $c)";
14 my @ret = $v->multi_return();
15 say "Got: ".scalar(@ret)." values: @ret";
16
17 $v->another(54);
18
19 my $param = { a => 1 };
20 my $s = "Hello You";
21 print "These should be called with a valid substr:\n";
22 RSPM::Foo142::test(substr($s, 3, 3));
23 RSPM::Foo142::teststr(substr($s, 3, 3));
24 print "Parameter exists: " . (exists($param->{x}) ? "YES" : "NO") . "\n";
25 RSPM::Foo142::test($param->{x});
26 print "Was auto-vivified: " . (exists($param->{x}) ? "YES" : "NO") . "\n";
27 RSPM::Foo142::teststr($param->{x});
28
29 my $a = "Can I have some coffee please?\n";
30 print $a;
31 my $b = RSPM::Foo142::test_serde($a);
32 print $b;
33 my $c = RSPM::Foo142::test_serde($b);
34 print $c;
35
36 use utf8;
37 binmode STDOUT, ':utf8';
38 my $a = "Can I have some ☕ please?\n";
39 print $a;
40 my $b = RSPM::Foo142::test_serde($a);
41 print $b;
42 my $c = RSPM::Foo142::test_serde($b);
43 print $c;
44
45 sub 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
66 to_string({ 'tristate' => '0' });
67 to_string({ 'tristate' => '1' });
68 to_string({ 'tristate' => undef });