Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions jemplate
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ package Number::Compare;
use strict;
use Carp qw(croak);
use vars qw/$VERSION/;
$VERSION = '0.03';
$VERSION = '0.01';

sub new {
my $referent = shift;
Expand All @@ -59,7 +59,7 @@ sub parse_to_perl {

my $comparison = $1 || '==';
my $target = $2;
my $magnitude = $3 || '';
my $magnitude = $3;
$target *= 1000 if lc $magnitude eq 'k';
$target *= 1024 if lc $magnitude eq 'ki';
$target *= 1000000 if lc $magnitude eq 'm';
Expand Down Expand Up @@ -10370,9 +10370,16 @@ sub _attempt_range_expand_val ($) {
return $val unless
my ( $from, $to ) = $val =~ m/\s*\[\s*(\S+)\s*\.\.\s*(\S+)\s*\]/;

die "Range expansion is current supported for positive/negative integer values only (e.g. [ 1 .. 10 ])\nCannot expand: $val" unless $from =~ m/^-?\d+$/ && $to =~ m/^-?\d+$/;
if ($from =~ m{^(["'])\w+\1$} && $to =~ m{(["'])\w+\1$}) {
(undef, $from) = $from =~ m{^(["'])(\w+)\1$};
(undef, $to ) = $to =~ m{^(["'])(\w+)\1$};
return join '', '[', join( ',', map("'$_'", ($from .. $to) ) ), ']';
} elsif ($from =~ m/^-?\d+$/ && $to =~ m/^-?\d+$/) {
return join '', '[', join( ',', $from .. $to ), ']';
} else {
die "Range expansion is current only supported for positive/negative integer values ([ 1 .. 10 ]) and word characters ('a'..'z')(\nCannot expand: $val";
}

return join '', '[', join( ',', $from .. $to ), ']';
}


Expand Down
12 changes: 10 additions & 2 deletions lib/Jemplate/Directive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ $block
}

# Try to do 1 .. 10 expansions
# and 'word'..'otherword' expansions
sub _attempt_range_expand_val ($) {
my $val = shift;
return $val unless
my ( $from, $to ) = $val =~ m/\s*\[\s*(\S+)\s*\.\.\s*(\S+)\s*\]/;

die "Range expansion is current supported for positive/negative integer values only (e.g. [ 1 .. 10 ])\nCannot expand: $val" unless $from =~ m/^-?\d+$/ && $to =~ m/^-?\d+$/;
if ($from =~ m{^(["'])\w+\1$} && $to =~ m{(["'])\w+\1$}) {
(undef, $from) = $from =~ m{^(["'])(\w+)\1$};
(undef, $to ) = $to =~ m{^(["'])(\w+)\1$};
return join '', '[', join( ',', map("'$_'", ($from .. $to) ) ), ']';
} elsif ($from =~ m/^-?\d+$/ && $to =~ m/^-?\d+$/) {
return join '', '[', join( ',', $from .. $to ), ']';
} else {
die "Range expansion is current only supported for positive/negative integer values ([ 1 .. 10 ]) and word characters ('a'..'z')(\nCannot expand: $val";
}

return join '', '[', join( ',', $from .. $to ), ']';
}

#------------------------------------------------------------------------
Expand Down