use base qw(Squirrel::Template::Expr::WrapBase);
use Scalar::Util ();
-our $VERSION = "1.001";
+our $VERSION = "1.002";
my $list_make_key = sub {
my ($item, $field) = @_;
return scalar(@{$self->[0]});
}
+sub _do_expand {
+ my ($self, $args) = @_;
+
+ @$args == 0
+ or die [ error => "list.expand takes no parameters" ];
+
+ return
+ [ map {
+ defined
+ && ref
+ && !Scalar::Util::blessed($_)
+ && Scalar::Util::reftype($_) eq 'ARRAY'
+ ? @$_
+ : $_
+ } @{$self->[0]} ];
+}
+
sub call {
my ($self, $method, $args) = @_;
Add the given elements to the start of the array. returns the new
size of the array.
+=item expand
+
+Return a new array with any contained arrays expanded one level.
+
+ [ [ [ 1 ], 2 ], 3 ].expand => [ [ 1 ], 2, 3 ]
+
=back
=head1 SEE ALSO
#!perl -w
# Basic tests for Squirrel::Template
use strict;
-use Test::More tests => 155;
+use Test::More tests => 156;
sub template_test($$$$;$$);
[ '(10).ceil', 10 ],
[ '(10.1).ceil', 11 ],
[ '(-10.1).ceil', -10 ],
+
+ # WrapArray
+ [ '[ [ 1, 2 ], 3 ].expand.join(",")', "1,2,3" ],
);
for my $test (@expr_tests) {
my ($expr, $result) = @$test;