package Squirrel::Template::Expr::WrapHash;
use strict;
use base qw(Squirrel::Template::Expr::WrapBase);
+use Scalar::Util;
-our $VERSION = "1.007";
+our $VERSION = "1.008";
sub _do_size {
my ($self) = @_;
return $args->[1];
}
+sub _do_extend {
+ my ($self, $args) = @_;
+
+ my %out = %{$self->[0]};
+ for my $arg (@$args) {
+ Scalar::Util::reftype($arg) eq "HASH"
+ or die "Argument to extend() isn't a hash\n";
+ Scalar::Util::blessed($args)
+ and die "Argument to extend() can't be blessed\n";
+
+ @out{keys %$arg} = values %$arg;
+ }
+
+ return \%out;
+}
+
sub _do_is_list {
return 0;
}
Always true for hashes.
+=item extend(hash1, ...)
+
+Return a new hash that is a shallow copy of the subject hash, with
+keys from the parameter hashes added or replacing existing keys.
+
=back
=head1 SEE ALSO
#!perl -w
# Basic tests for Squirrel::Template
use strict;
-use Test::More tests => 188;
+use Test::More tests => 189;
use HTML::Entities;
sub template_test($$$$;$$);
# WrapHash
[ '{ "foo": 1 }.is_list', 0 ],
[ '{ "foo": 1 }.is_hash', 1 ],
+ [ '{ foo: 1, bar: 1 }.extend({ bar:2 })["bar"]', 2 ],
);
for my $test (@expr_tests) {
my ($expr, $result) = @$test;