-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Flower::Utils::Debug, implements dump: and what: modifiers.
- Loading branch information
1 parent
f4f1de1
commit 76ae95b
Showing
4 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Flower::Utils::Perl; | ||
|
||
## Like it's cousins 'python:' and 'php:', the 'perl:' modifier allows | ||
## you to query the data using the native Perl 6 format instead of the | ||
## path syntax. Example: <eg tal:replace="perl:my-hash<key>.method('param')" /> | ||
## The 'my-hash' in the example must be a valid key in the Flower data. | ||
|
||
our sub all() { | ||
my %modifiers = { | ||
dump => &dump_perl, | ||
what => &what_perl, | ||
}; | ||
return %modifiers; | ||
} | ||
|
||
our sub dump_perl($parent, $query, *%opts) { | ||
my $result = $parent.query($query); | ||
return $result.perl; | ||
} | ||
|
||
our sub what_perl($parent, $query, *%opts) { | ||
my $result = $parent.query($query); | ||
return $result.WHAT.perl; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env perl6 | ||
|
||
BEGIN { @*INC.unshift: './lib' } | ||
|
||
use Test; | ||
use Flower; | ||
use Flower::Utils::Debug; | ||
|
||
plan 1; | ||
|
||
my $xml = '<?xml version="1.0"?>'; | ||
|
||
my $template = '<test><dump tal:content="dump:object" tal:attributes="type what:object"/></test>'; | ||
my $flower = Flower.new(:template($template)); | ||
|
||
my %ahash = { | ||
'anarray' => [ 'one', 'two', 'three' ], | ||
} | ||
|
||
$flower.add-modifiers(Flower::Utils::Perl::all()); | ||
|
||
is $flower.parse(object => %ahash), $xml~'<test><dump type="Hash">{"anarray" => ["one", "two", "three"]}</dump></test>', 'dump: and what: modifiers'; | ||
|