Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Flower::Utils::Debug, implements dump: and what: modifiers.

  • Loading branch information...
commit 76ae95be350006b02e78c07502804a2dc27132fa 1 parent f4f1de1
@supernovus authored
View
9 README
@@ -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
View
1  docs/TODO.txt
@@ -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.
View
25 lib/Flower/Utils/Debug.pm
@@ -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;
+}
+
View
23 t/06-debug-modifier.t
@@ -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';
+
Please sign in to comment.
Something went wrong with that request. Please try again.