Skip to content

Commit

Permalink
Merge pull request #5 from cognominal/master
Browse files Browse the repository at this point in the history
Fixed to support EVAL and :exists
  • Loading branch information
supernovus committed Sep 21, 2014
2 parents 01f274a + be6e544 commit 9bff4b8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions lib/Template6/Context.pm6
Expand Up @@ -24,7 +24,7 @@ has %.providers; ## Providers for templates, based on prefix names.

submethod BUILD (*%args) {
$!service = %args<service>;
if (!%args.exists('context')) {
unless %args<context> :exists {
%args<context> = self;
}
if (%args<parser>) {
Expand All @@ -49,13 +49,13 @@ method add-provider ($name, $object) {
## A couple of helper methods for the default provider.

method add-path ($path) {
if %!providers.exists('file') {
if %!providers<file> :exists {
%!providers<file>.add-path($path);
}
}

method set-extension ($ext) {
if %!providers.exists('file') {
if %!providers<file> :exists {
%!providers<file>.ext = $ext;
}
}
Expand All @@ -67,7 +67,7 @@ method get-template-text ($name is copy) {
$prefix = $0;
}

if $prefix.defined && %!providers.exists{$prefix} {
if $prefix.defined && (%!providers{$prefix} :exists) {
@providers = %!providers{$prefix};
}
else {
Expand All @@ -82,11 +82,11 @@ method get-template-text ($name is copy) {
}

method get-template-block ($name) {
if %.blocks.exists($name) {
if %.blocks{$name} :exists {
return %.blocks{$name};
}
for @.block-cache -> $known-blocks {
if $known-blocks.exists($name) {
if $known-blocks{$name} :exists {
return $known-blocks{$name};
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Template6/Parser.pm6
Expand Up @@ -193,7 +193,7 @@ method compile ($template) {
}
$script ~= "return \$output;\n\}";
# $*ERR.say: "<DEBUG:template>\n$script\n</DEBUG:template>";
my $function = eval $script;
my $function = EVAL $script;
return $function;
}

2 changes: 1 addition & 1 deletion lib/Template6/Provider/File.pm6
Expand Up @@ -20,7 +20,7 @@ method add-path ($path) {
}

method fetch ($name) {
if %.templates.exists($name) {
if %.templates{$name} :exists {
return %.templates{$name};
}
for @.include-path -> $path {
Expand Down
4 changes: 2 additions & 2 deletions lib/Template6/Service.pm6
Expand Up @@ -15,12 +15,12 @@ submethod BUILD (*%args) {
$!context = %args<context>;
}
else {
if (!%args.exists('service')) {
unless %args<service> :exists {
%args<service> = self;
}
$!context = Template6::Context.new(|%args);
}
if %args.exists('reset') {
if %args<reset> :exists {
$!reset = %args<reset>;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Template6/Stash.pm6
Expand Up @@ -13,7 +13,7 @@ method lookup (@query is rw, $data) {
my $element = @query.shift;
my $found;
if $data ~~ Hash {
if $data.exists($element) {
if $data{$element} :exists {
$found = $data{$element};
}
}
Expand All @@ -37,7 +37,7 @@ method lookup (@query is rw, $data) {
}

method get ($query, :$strict) {
if %!data.exists($query) {
if %!data{$query} :exists {
return %!data{$query};
}
elsif ($query ~~ /\./) {
Expand Down
6 changes: 3 additions & 3 deletions t/02-for.t
Expand Up @@ -61,12 +61,12 @@ $wanted = "<html>
</html>
";

my %users =
{
my %users = %(

'bob@smith.com' => 27,
'lisa@abbot.org' => 18,
'melissa@senstry.com' => 31,
};
);

is $t6.process('for-hash', :title<For Hash Test>, :users(%users)), $wanted, 'For statement with hash.';

0 comments on commit 9bff4b8

Please sign in to comment.