1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-11 00:52:44 +03:00
mal/perl/interop.pm
Joel Martin 01c9731649 All: swap step9,A. Fixes for bash, C, perl.
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.
2015-01-06 21:57:24 -06:00

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;