use Scalar::Util ();
use List::Util ();
-our $VERSION = "1.007";
+our $VERSION = "1.008";
my $list_make_key = sub {
my ($item, $field) = @_;
return $args->[1];
}
+sub _do_as_hash {
+ my ($self, $args) = @_;
+
+ @$args == 0
+ or die [ error => "list.as_hash takes no parameters" ];
+
+ my @extra = @{$self->[0]} % 2 ? ( undef ) : ();
+
+ return +{ @{$self->[0]}, @extra };
+}
+
sub call {
my ($self, $method, $args) = @_;
Set the specified I<index> in the array to I<value>. Returns
I<value>.
+=item as_hash
+
+Returns a hash formed as if the array was formed of key and value
+pairs. If the number of elements is odd, the value for the odd key is
+C<undef>.
+
+ [ "a", 1, "b", 2 ].as_hash => { a:1, b:2 }
+
=item is_list
Test if this object is a list. Always true for a list.
#!perl -w
# Basic tests for Squirrel::Template
use strict;
-use Test::More tests => 187;
+use Test::More tests => 188;
use HTML::Entities;
sub template_test($$$$;$$);
[ '[ 1, 2 ].is_list', 1 ],
[ '[ 1, 2 ].is_hash', 0 ],
[ '[ 1 .. 5 ].shuffle.size', 5 ],
+ [ '([ "a", 1, "b", "2" ].as_hash)["a"]', 1 ],
# WrapHash
[ '{ "foo": 1 }.is_list', 0 ],