Skip to content

Commit

Permalink
Added Flower::Utils::Debug, implements dump: and what: modifiers.
Browse files Browse the repository at this point in the history
  • Loading branch information
supernovus committed Oct 7, 2010
1 parent f4f1de1 commit 76ae95b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
9 changes: 5 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ modifiers. The following sets are planned for inclusion:
will get its standard stringification form (ISO by default.)
- Perl, makes a 'perl:' modifier available, which is the counterpart
to Zope's 'python:' or PHPTAL's 'php:' modifiers.
- Debug, similar to :debug set from Petal::Utils.
dump: modifier spits out the .perl representation of the object.
what: modifier spits out the class name of the object.

URI is not included (feel free to write it if you need it) and neither is
Debug, but that's okay, because dump:
is built into Flower (it does a .perl on the object.) I'm sure new exciting
libraries will be made adding onto these (a JSON dumper would be nice.)
URI is not included (feel free to write it if you need it.)
I'm sure new exciting libraries will be made adding onto these.

= Author: Timothy Totten
= License: Artistic License 2.0
Expand Down
1 change: 0 additions & 1 deletion docs/TODO.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Short Term (October 2010)
- Implement XML escaping on text nodes.
- Finish implementing Flower::Utils, as per the README.
- Add dump: handler to DefaultHandlers, as per the README.

Medium Term (December 2010)
- Implement METAL support.
Expand Down
25 changes: 25 additions & 0 deletions lib/Flower/Utils/Debug.pm
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;
}

23 changes: 23 additions & 0 deletions t/06-debug-modifier.t
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';

0 comments on commit 76ae95b

Please sign in to comment.