mirror of
https://github.com/kanaka/mal.git
synced 2024-11-10 12:47:45 +03:00
01c9731649
step9_interop -> stepA_interop stepA_more -> step9_try C: fix glib headers bash: behavior change of declare -A and pattern replacement. perl: squelch new 5.18 warnings related to switch/given statement. Also, include some in-progress interop related files.
37 lines
846 B
Perl
37 lines
846 B
Perl
package interop;
|
|
use strict;
|
|
use warnings FATAL => qw(all);
|
|
no if $] >= 5.018, warnings => "experimental::smartmatch";
|
|
use feature qw(switch);
|
|
use Exporter 'import';
|
|
our @EXPORT_OK = qw( pl_to_mal );
|
|
use Scalar::Util qw(looks_like_number);
|
|
|
|
use types;
|
|
|
|
sub pl_to_mal {
|
|
my($obj) = @_;
|
|
given (ref $obj) {
|
|
when(/^ARRAY/) {
|
|
my @arr = map {pl_to_mal($_)} @$obj;
|
|
return List->new(\@arr);
|
|
}
|
|
when(/^HASH/) {
|
|
my $hsh = {};
|
|
foreach my $key (keys %$obj) {
|
|
$hsh->{$key} = pl_to_mal($obj->{$key});
|
|
}
|
|
return HashMap->new($hsh)
|
|
}
|
|
default {
|
|
if (looks_like_number($obj)) {
|
|
return Integer->new($obj);
|
|
} else {
|
|
return String->new($obj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
1;
|