Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Work in progress, nearly there!

  • Loading branch information...
commit 85d83073b201482e4dd77b0f76e651b45436142c 1 parent 0f62e14
Timothy Totten authored October 13, 2011
7  lib/Flower.pm6
@@ -40,6 +40,9 @@ method !get-plugin ($plugin) {
40 40
   my $object = $plugin;
41 41
   if ! $plugin.defined {
42 42
     $object = $plugin.new(:flower(self));
  43
+    if $object.can('init') {
  44
+      $object.init();
  45
+    }
43 46
   }
44 47
   return $object;
45 48
 }
@@ -55,10 +58,11 @@ multi method parse (Exemel::Document $template, *%data) {
55 58
     %rootattrs{$val} = $key; ## Yeah, we're reversing it.
56 59
   }
57 60
   for @.plugins -> $plugin {
  61
+    $plugin.custom-tag = Nil;
58 62
     if %rootattrs.exists($plugin.ns) {
59 63
       my $tag = %rootattrs{$plugin.ns};
60 64
       $tag ~~ s/^xmlns\://;
61  
-      $plugin.tag = $tag;
  65
+      $plugin.custom-tag = $tag;
62 66
     }
63 67
   }
64 68
 
@@ -169,6 +173,7 @@ method parse-element($element is rw, :$safe) {
169 173
       }
170 174
       if ! $meth { next; } ## Undefined method, we can't handle that.
171 175
       my $fullname = $plugin.tag ~ ':' ~ $name;
  176
+#      $*ERR.say: "-- Parsing $fullname tags";
172 177
       if $isel {
173 178
         if $element.name eq $fullname {
174 179
           $plugin."$meth"($element, $fullname);
15  lib/Flower/Lang.pm6
... ...
@@ -0,0 +1,15 @@
  1
+role Flower::Lang;
  2
+
  3
+## Common methods for Flower Languages.
  4
+
  5
+has $.flower;
  6
+has $.custom-tag is rw;
  7
+has %.options;
  8
+
  9
+method tag {
  10
+  if $.custom-tag.defined {
  11
+    return $.custom-tag;
  12
+  }
  13
+  return $.default-tag;
  14
+}
  15
+
23  lib/Flower/TAL.pm6
... ...
@@ -0,0 +1,23 @@
  1
+use Flower;
  2
+class Flower::TAL is Flower; 
  3
+
  4
+## Extend Flower into a TAL/METAL engine.
  5
+
  6
+use Flower::TAL::TAL;
  7
+use Flower::TAL::METAL;
  8
+
  9
+our submethod BUILD () {
  10
+  self.add-plugin(Flower::TAL::METAL); ## We parse METAL first.
  11
+  self.add-plugin(Flower::TAL::TAL);   ## Then we parse TAL.
  12
+}
  13
+
  14
+## Add a TALES plugin.
  15
+method add-tales ($tale) {
  16
+  for @.plugins -> $plugin {
  17
+    if $plugin ~~ Flower::TAL::TAL {
  18
+      $plugin.tales.add-plugin($tale);
  19
+      last;
  20
+    }
  21
+  }
  22
+}
  23
+
27  lib/Flower/TAL/METAL.pm6
... ...
@@ -1,9 +1,11 @@
1  
-class Flower::TAL::METAL; ## The METAL XML Application Language.
  1
+#use Flower::Lang;
  2
+class Flower::TAL::METAL; # does Flower::Lang; 
  3
+
  4
+## The METAL XML Application Language.
2 5
 
3 6
 use Exemel;
4 7
 
5  
-has $.flower;
6  
-has $.tag is rw = 'metal';
  8
+has $.default-tag = 'metal';
7 9
 has $.ns = 'http://xml.zope.org/namespaces/metal';
8 10
 
9 11
 ## The tags for METAL macro processing.
@@ -12,15 +14,28 @@ has @.handlers =
12 14
   'define-macro' => 'parse-define',
13 15
   'use-macro'    => 'parse-use';
14 16
 
15  
-## Needed by the spec, but unused here.
16  
-has %.options; 
17  
-
18 17
 ## The cache for METAL macros.
19 18
 has %.metal is rw;
20 19
 
21 20
 ## The cache for included XML templates.
22 21
 has %.file is rw;
23 22
 
  23
+## Common methods for Flower Languages.
  24
+## This is in Flower::Lang role, but due to bugs with having
  25
+## multiple classes using the same roles in Rakudo ng, I've simply
  26
+## copied and pasted it. Oh, I can't wait until this works on "nom".
  27
+
  28
+has $.flower;
  29
+has $.custom-tag is rw;
  30
+has %.options;
  31
+
  32
+method tag {
  33
+  if $.custom-tag.defined {
  34
+    return $.custom-tag;
  35
+  }
  36
+  return $.default-tag;
  37
+}
  38
+
24 39
 ## Loading more XML documents.
25 40
 ## Now caches results, for easy re-use.
26 41
 method load-xml-file ($filename) {
51  lib/Flower/TAL/TAL.pm6
... ...
@@ -1,12 +1,14 @@
1  
-class Flower::TAL::TAL; ## The TAL XML Application Language
  1
+#use Flower::Lang;
  2
+class Flower::TAL::TAL; #does Flower::Lang; 
  3
+
  4
+## The TAL XML Application Language
2 5
 
3 6
 use Exemel;
4 7
 
5 8
 use Flower::TAL::TALES;  ## The TALES attribute sub-language.
6 9
 use Flower::TAL::Repeat; ## A class representing our repeat object.
7 10
 
8  
-has $.flower; 
9  
-has $.tag is rw = 'tal';    
  11
+has $.default-tag = 'tal';  ## What to use if nothing is set.
10 12
 has $.ns = 'http://xml.zope.org/namespaces/tal';
11 13
 
12 14
 ## The full set of TAL attributes.
@@ -22,19 +24,34 @@ has @.handlers =
22 24
   'omit-tag'     => 'parse-omit',
23 25
   'block'        => { :element }; ## lazy <tal:block> extension from PHPTAL.
24 26
 
25  
-## Needed by the spec, but unused here.
  27
+has $.tales;
  28
+
  29
+## Common methods for Flower Languages.
  30
+## This is in Flower::Lang role, but due to bugs with having
  31
+## multiple classes using the same roles in Rakudo ng, I've simply
  32
+## copied and pasted it. Oh, I can't wait until this works on "nom".
  33
+
  34
+has $.flower;
  35
+has $.custom-tag is rw;
26 36
 has %.options;
27 37
 
28  
-has $.tales;
  38
+method tag {
  39
+  if $.custom-tag.defined {
  40
+    return $.custom-tag;
  41
+  }
  42
+  return $.default-tag;
  43
+}
29 44
 
30  
-our submethod BUILD (:$flower) {
31  
-  $!flower = $flower;
  45
+## Normally we'd use submethod BUILD but in "ng" at least, it
  46
+## completely wipes out our defaults in the "has" statements.
  47
+## Boo, hiss. So now we have this lovely bit of magic instead.
  48
+method init () {
32 49
   $!tales  = Flower::TAL::TALES.new(:parent(self));
33 50
 }
34 51
 
35 52
 ## This is super simple, as a <tal:block> acts the
36 53
 ## same as a normal element with a  tal:omit-tag="" rule.
37  
-method parse_block ($element is rw, $name) {
  54
+method parse-block ($element is rw, $name) {
38 55
   $element = $element.nodes;
39 56
 }
40 57
 
@@ -42,8 +59,8 @@ method parse-define ($xml is rw, $tag) {
42 59
   my @statements = $xml.attribs{$tag}.split(/\;\s+/);
43 60
   for @statements -> $statement {
44 61
     my ($attrib, $query) = $statement.split(/\s+/, 2);
45  
-    my $val = self.query($query);
46  
-    if defined $val { %.data{$attrib} = $val; }
  62
+    my $val = $.tales.query($query);
  63
+    if defined $val { $.flower.data{$attrib} = $val; }
47 64
   }
48 65
   $xml.unset($tag);
49 66
 }
@@ -94,24 +111,24 @@ method parse-repeat ($xml is rw, $tag) {
94 111
   my ($attrib, $query) = $xml.attribs{$tag}.split(/\s+/, 2);
95 112
   my $array = $.tales.query($query);
96 113
   if (defined $array && $array ~~ Array) {
97  
-    if (! %.data.exists('repeat') || %.data<repeat> !~~ Hash) {
98  
-      %.data<repeat> = {}; # Initialize the repeat hash.
  114
+    if (! $.flower.data.exists('repeat') || $.flower.data<repeat> !~~ Hash) {
  115
+      $.flower.data<repeat> = {}; # Initialize the repeat hash.
99 116
     }
100 117
     $xml.unset($tag);
101 118
     my @elements;
102 119
     my $count = 0;
103 120
     for @($array) -> $item {
104 121
       my $newxml = $xml.deep-clone;
105  
-      %.data{$attrib} = $item;
  122
+      $.flower.data{$attrib} = $item;
106 123
       my $repeat = Flower::TAL::Repeat.new(:index($count), :length($array.elems));
107  
-      %.data<repeat>{$attrib} = $repeat;
  124
+      $.flower.data<repeat>{$attrib} = $repeat;
108 125
       my $wrapper = Exemel::Element.new(:nodes(($newxml)));
109  
-      self.parse-elements($wrapper);
  126
+      $.flower.parse-elements($wrapper);
110 127
       @elements.push: @($wrapper.nodes);
111 128
       $count++;
112 129
     }
113  
-    %.data<repeat>.delete($attrib);
114  
-    %.data.delete($attrib);
  130
+    $.flower.data<repeat>.delete($attrib);
  131
+    $.flower.data.delete($attrib);
115 132
     $xml = @elements;
116 133
   }
117 134
   else {
16  t/01-basics.t
@@ -5,7 +5,7 @@ BEGIN { @*INC.unshift: './lib' }
5 5
 use Test;
6 6
 use Flower::TAL;
7 7
 
8  
-plan 10;
  8
+plan 9; ## from outer space.
9 9
 
10 10
 sub attrmake (*@opts) { @opts.join(' ') | @opts.reverse.join(' ') }
11 11
 
@@ -61,17 +61,3 @@ is ~$tal.parse($template, test=>'Hello World'), $xml~'<test xmlns:petal="http://
61 61
 $template = '<test tal:attributes="id id">Test document</test>';
62 62
 is ~$tal.parse($template, id=>'first'), $xml~'<test id="first">Test document</test>', 'attributes on root document';
63 63
 
64  
-## test 10
65  
-
66  
-my @options = (
67  
-  { value => 'a', label => 'Option 1' },
68  
-  { value => 'b', label => 'Option 2', selected => 'selected' },
69  
-  { value => 'c', label => 'Option 3' },
70  
-);
71  
-
72  
-$template = '<select><option tal:repeat="option options" tal:attributes="value option/value; selected option/selected" tal:content="option/label"/></select>';
73  
-
74  
-$attrpos = attrmake 'value="b"', 'selected="selected"';
75  
-
76  
-is ~$tal.parse($template, options => @options), $xml~'<select><option value="a">Option 1</option><option '~$attrpos~'>Option 2</option><option value="c">Option 3</option></select>', 'attributes with undefined value';
77  
-
47  t/02-repeat.t
@@ -3,35 +3,33 @@
3 3
 BEGIN { @*INC.unshift: './lib' }
4 4
 
5 5
 use Test;
6  
-use Flower;
  6
+use Flower::TAL;
7 7
 
8  
-plan 8;
  8
+plan 9; ## also from outer space.
9 9
 
10 10
 my $xml = '<?xml version="1.0"?>';
11 11
 
12 12
 ## test 1
13 13
 
14 14
 my $template = '<test><item tal:repeat="item items" tal:attributes="alt item/alt" tal:content="item/content"/></test>';
15  
-my $flower = Flower.new(:template($template));
  15
+my $tal = Flower::TAL.new();
16 16
 my @items = (
17 17
   { :alt<One>,   :content<First>  },
18 18
   { :alt<Two>,   :content<Second> },
19 19
   { :alt<Three>, :content<Third>  },
20 20
 );
21 21
 
22  
-is $flower.parse(:items(@items)), $xml~'<test><item alt="One">First</item><item alt="Two">Second</item><item alt="Three">Third</item></test>', 'tal:repeat';
  22
+is ~$tal.parse($template, :items(@items)), $xml~'<test><item alt="One">First</item><item alt="Two">Second</item><item alt="Three">Third</item></test>', 'tal:repeat';
23 23
 
24 24
 ## test 2
25 25
 
26 26
 $template = '<test><div tal:repeat="item items" tal:omit-tag=""><tr><td tal:content="item/alt"/><td tal:content="item/content"/></tr></div></test>';
27  
-$flower.=another(:template($template));
28  
-is $flower.parse(:items(@items)), $xml~'<test><tr><td>One</td><td>First</td></tr><tr><td>Two</td><td>Second</td></tr><tr><td>Three</td><td>Third</td></tr></test>', 'tal:repeat with nested elements and omit-tag';
  27
+is ~$tal.parse($template, :items(@items)), $xml~'<test><tr><td>One</td><td>First</td></tr><tr><td>Two</td><td>Second</td></tr><tr><td>Three</td><td>Third</td></tr></test>', 'tal:repeat with nested elements and omit-tag';
29 28
 
30 29
 ## test 3, Here we test tal:block as well.
31 30
 
32 31
 $template = '<test><tal:block tal:repeat="item items"><tr><td tal:content="item/alt"/><td tal:content="item/content"/></tr></tal:block></test>';
33  
-$flower.=another(:template($template));
34  
-is $flower.parse(:items(@items)), $xml~'<test><tr><td>One</td><td>First</td></tr><tr><td>Two</td><td>Second</td></tr><tr><td>Three</td><td>Third</td></tr></test>', 'tal:block used in repeat';
  32
+is ~$tal.parse($template, :items(@items)), $xml~'<test><tr><td>One</td><td>First</td></tr><tr><td>Two</td><td>Second</td></tr><tr><td>Three</td><td>Third</td></tr></test>', 'tal:block used in repeat';
35 33
 
36 34
 ## test 4, Now we're going to test the repeat object.
37 35
 
@@ -43,38 +41,45 @@ my @rows = (
43 41
   [ '3.1', '3.2', '3.3' ],
44 42
 );
45 43
 
46  
-$flower.=another(:template($template));
47  
-is $flower.parse(:rows(@rows)), $xml~'<table><tr><td>1 / 1 = 1.1</td><td>1 / 2 = 1.2</td><td>1 / 3 = 1.3</td></tr><tr><td>2 / 1 = 2.1</td><td>2 / 2 = 2.2</td><td>2 / 3 = 2.3</td></tr><tr><td>3 / 1 = 3.1</td><td>3 / 2 = 3.2</td><td>3 / 3 = 3.3</td></tr></table>', 'nested repeat numbers';
  44
+is ~$tal.parse($template, :rows(@rows)), $xml~'<table><tr><td>1 / 1 = 1.1</td><td>1 / 2 = 1.2</td><td>1 / 3 = 1.3</td></tr><tr><td>2 / 1 = 2.1</td><td>2 / 2 = 2.2</td><td>2 / 3 = 2.3</td></tr><tr><td>3 / 1 = 3.1</td><td>3 / 2 = 3.2</td><td>3 / 3 = 3.3</td></tr></table>', 'nested repeat numbers';
48 45
 
49 46
 ## test 5
50 47
 
51 48
 $template = '<test><tal:block tal:repeat="item items"><item tal:condition="repeat/item/odd" tal:attributes="id repeat/item/index">Odd</item><item tal:condition="repeat/item/even" tal:attributes="id repeat/item/index">Even</item></tal:block></test>';
52 49
 
53  
-$flower.=another(:template($template));
54  
-
55  
-is $flower.parse(:items([1..4])), $xml~'<test><item id="0">Odd</item><item id="1">Even</item><item id="2">Odd</item><item id="3">Even</item></test>', 'repeat with odd and even conditionals';
  50
+is ~$tal.parse($template, :items([1..4])), $xml~'<test><item id="0">Odd</item><item id="1">Even</item><item id="2">Odd</item><item id="3">Even</item></test>', 'repeat with odd and even conditionals';
56 51
 
57 52
 ## test 6
58 53
 
59 54
 $template = '<test><tal:block tal:repeat="item items"><item tal:condition="repeat/item/start">First</item><item tal:condition="repeat/item/inner">Inner</item><item tal:condition="repeat/item/end" tal:attributes="length repeat/item/length">Last</item></tal:block></test>';
60 55
 
61  
-$flower.=another(:template($template));
62  
-
63  
-is $flower.parse(:items([1..4])), $xml~'<test><item>First</item><item>Inner</item><item>Inner</item><item length="4">Last</item></test>', 'repeat with start, end, inner and length.';
  56
+is ~$tal.parse($template, :items([1..4])), $xml~'<test><item>First</item><item>Inner</item><item>Inner</item><item length="4">Last</item></test>', 'repeat with start, end, inner and length.';
64 57
 
65 58
 ## test 7
66 59
 
67 60
 $template = '<test><tal:block tal:repeat="item items"><item tal:condition="repeat/item/every \'3\'">Every third</item><item tal:condition="repeat/item/skip \'3\'">Normal item</item></tal:block></test>';
68 61
 
69  
-$flower.=another(:template($template));
70  
-
71  
-is $flower.parse(:items([1..7])), $xml~'<test><item>Normal item</item><item>Normal item</item><item>Every third</item><item>Normal item</item><item>Normal item</item><item>Every third</item><item>Normal item</item></test>', 'repeat with every and skip';
  62
+is ~$tal.parse($template, :items([1..7])), $xml~'<test><item>Normal item</item><item>Normal item</item><item>Every third</item><item>Normal item</item><item>Normal item</item><item>Every third</item><item>Normal item</item></test>', 'repeat with every and skip';
72 63
 
73 64
 ## test 8
74 65
 
75 66
 $template = '<test><tal:block tal:repeat="item items"><item tal:condition="repeat/item/lt \'3\'">lt 3</item><item tal:condition="repeat/item/gt \'3\'">gt 3</item><item tal:condition="repeat/item/eq \'3\'">the third</item></tal:block></test>';
76 67
 
77  
-$flower.=another(:template($template));
  68
+is ~$tal.parse($template, :items([1..5])), $xml~'<test><item>lt 3</item><item>lt 3</item><item>the third</item><item>gt 3</item><item>gt 3</item></test>', 'repeat with gt, lt and eq';
  69
+
  70
+## test 9
  71
+
  72
+sub attrmake (*@opts) { @opts.join(' ') | @opts.reverse.join(' ') }
  73
+
  74
+my @options = (
  75
+  { value => 'a', label => 'Option 1' },
  76
+  { value => 'b', label => 'Option 2', selected => 'selected' },
  77
+  { value => 'c', label => 'Option 3' },
  78
+);
  79
+
  80
+$template = '<select><option tal:repeat="option options" tal:attributes="value option/value; selected option/selected" tal:content="option/label"/></select>';
  81
+
  82
+my $attrpos = attrmake 'value="b"', 'selected="selected"';
78 83
 
79  
-is $flower.parse(:items([1..5])), $xml~'<test><item>lt 3</item><item>lt 3</item><item>the third</item><item>gt 3</item><item>gt 3</item></test>', 'repeat with gt, lt and eq';
  84
+is ~$tal.parse($template, options => @options), $xml~'<select><option value="a">Option 1</option><option '~$attrpos~'>Option 2</option><option value="c">Option 3</option></select>', 'attributes with undefined value';
80 85
 
9  t/03-default.t
@@ -3,7 +3,7 @@
3 3
 BEGIN { @*INC.unshift: './lib' }
4 4
 
5 5
 use Test;
6  
-use Flower;
  6
+use Flower::TAL;
7 7
 
8 8
 plan 2;
9 9
 
@@ -12,15 +12,14 @@ my $xml = '<?xml version="1.0"?>';
12 12
 ## test 1
13 13
 
14 14
 my $template = '<test><i tal:content="default">The default text</i></test>';
15  
-my $flower = Flower.new(:template($template));
  15
+my $tal = Flower::TAL.new();
16 16
 
17  
-is $flower.parse(), $xml~'<test><i>The default text</i></test>', 'tal:content with default';
  17
+is ~$tal.parse($template), $xml~'<test><i>The default text</i></test>', 'tal:content with default';
18 18
 
19 19
 ## test 2
20 20
 
21 21
 $template = '<test><i tal:replace="default">The default text</i></test>';
22  
-$flower.=another(:template($template));
23 22
 
24  
-is $flower.parse(), $xml~'<test>The default text</test>', 'tal:replace with default';
  23
+is ~$tal.parse($template), $xml~'<test>The default text</test>', 'tal:replace with default';
25 24
 
26 25
 
6  t/03-escape.t
@@ -3,14 +3,14 @@
3 3
 BEGIN { @*INC.unshift: './lib' }
4 4
 
5 5
 use Test;
6  
-use Flower;
  6
+use Flower::TAL;
7 7
 
8 8
 plan 1;
9 9
 
10 10
 my $xml = '<?xml version="1.0"?>';
11 11
 
12 12
 my $template = '<test><escaped tal:content="string"/><unescaped tal:content="structure string"/></test>';
13  
-my $flower = Flower.new(:template($template));
  13
+my $tal = Flower::TAL.new();
14 14
 
15  
-is $flower.parse(string=>'hello to you & your friend, "how are you?"'), $xml~'<test><escaped>hello to you &amp; your friend, &quot;how are you?&quot;</escaped><unescaped>hello to you & your friend, "how are you?"</unescaped></test>', 'XML escapes and structure keyword';
  15
+is ~$tal.parse($template, string=>'hello to you & your friend, "how are you?"'), $xml~'<test><escaped>hello to you &amp; your friend, &quot;how are you?&quot;</escaped><unescaped>hello to you & your friend, "how are you?"</unescaped></test>', 'XML escapes and structure keyword';
16 16
 
13  t/03-methods.t
@@ -3,7 +3,7 @@
3 3
 BEGIN { @*INC.unshift: './lib' }
4 4
 
5 5
 use Test;
6  
-use Flower;
  6
+use Flower::TAL;
7 7
 
8 8
 class Person {
9 9
     method talk (*@args) {
@@ -12,12 +12,17 @@ class Person {
12 12
     }
13 13
 }
14 14
 
15  
-plan 1;
  15
+plan 2;
16 16
 
17 17
 my $xml = '<?xml version="1.0"?>';
18 18
 
19 19
 my $template = "<test><item tal:content=\"self/talk 'Tim'\"/></test>";
20  
-my $flower = Flower.new(:template($template));
  20
+my $tal = Flower::TAL.new();
21 21
 
22  
-is $flower.parse(:self(Person.new)), $xml~'<test><item>Why are you talking to yourself Tim?</item></test>', 'tal:content with method call';
  22
+my $person = Person.new;
  23
+
  24
+is ~$tal.parse($template, :self($person)), $xml~'<test><item>Why are you talking to yourself Tim?</item></test>', 'tal:content with method call';
  25
+
  26
+$template = "<test><item tal:content=\"self/talk\"/></test>";
  27
+is ~$tal.parse($template, :self($person)), $xml~'<test><item>Why are you talking to yourself weirdo?</item></test>', 'method call with no arguments.';
23 28
 
9  t/05-custom-modifiers.t
@@ -10,16 +10,17 @@ BEGIN {
10 10
 }
11 11
 
12 12
 use Test;
13  
-use Flower;
  13
+use Flower::TAL;
  14
+use Example::Modifiers;
14 15
 
15 16
 plan 1;
16 17
 
17 18
 my $xml = '<?xml version="1.0"?>';
18 19
 
19 20
 my $template = '<test><woah tal:replace="woah:crazy"/></test>';
20  
-my $flower = Flower.new(:template($template));
  21
+my $tal = Flower::TAL.new();
21 22
 
22  
-$flower.load-modifiers('Example::Modifiers');
  23
+$tal.add-tales(Example::Modifiers);
23 24
 
24  
-is $flower.parse(crazy => 'hello world'), $xml~'<test>Woah, hello world, that\'s awesome!</test>', 'custom modifiers';
  25
+is ~$tal.parse($template, crazy => 'hello world'), $xml~'<test>Woah, hello world, that\'s awesome!</test>', 'custom modifiers';
25 26
 
12  t/07-metal.t
@@ -3,7 +3,7 @@
3 3
 BEGIN { @*INC.unshift: './blib', './lib' }
4 4
 
5 5
 use Test;
6  
-use Flower;
  6
+use Flower::TAL;
7 7
 
8 8
 plan 3;
9 9
 
@@ -12,18 +12,16 @@ my $xml = '<?xml version="1.0"?>';
12 12
 ## test 1, basic define and use.
13 13
 
14 14
 my $template = '<test><zool metal:define-macro="hello">Hello World</zool><zed metal:use-macro="hello">Goodbye Universe</zed></test>';
15  
-my $flower = Flower.new(:template($template));
16  
-is $flower.parse(), $xml~'<test><zool>Hello World</zool><zool>Hello World</zool></test>', 'metal:define-macro and metal:use-macro';
  15
+my $tal = Flower.new();
  16
+is ~$flower.parse($template), $xml~'<test><zool>Hello World</zool><zool>Hello World</zool></test>', 'metal:define-macro and metal:use-macro';
17 17
 
18 18
 ## test 2, using from an external file.
19 19
 
20 20
 $template = '<test><zed metal:use-macro="./t/metal/common.xml#hello">Say Hi</zed></test>';
21  
-$flower.=another(:template($template));
22  
-is $flower.parse(), $xml~'<test><zool>Hello, World.</zool></test>', 'metal:use-macro with external reference.';
  21
+is ~$tal.parse($template), $xml~'<test><zool>Hello, World.</zool></test>', 'metal:use-macro with external reference.';
23 22
 
24 23
 ## test 3, slots.
25 24
 
26 25
 $template = '<test><zed metal:use-macro="./t/metal/common.xml#slotty">A slotty test, <orb metal:fill-slot="booya">Yippie Kai Yay!</orb>.</zed></test>';
27  
-$flower.=another(:template($template));
28  
-is $flower.parse(), $xml~'<test><zarf>It is known, <orb>Yippie Kai Yay!</orb> What do you think?</zarf></test>', 'metal:define-slot and metal:fill-slot';
  26
+is ~$tal.parse($template), $xml~'<test><zarf>It is known, <orb>Yippie Kai Yay!</orb> What do you think?</zarf></test>', 'metal:define-slot and metal:fill-slot';
29 27
 
15  t/lib/Example/Modifiers.pm
... ...
@@ -1,15 +0,0 @@
1  
-module Example::Modifiers;
2  
-
3  
-our sub export() {
4  
-  my %modifiers = {
5  
-    woah => &woahize,
6  
-  };
7  
-  return %modifiers;
8  
-}
9  
-
10  
-our sub woahize ($parent, $query, *%opts) {
11  
-  my $result = $parent.query($query);
12  
-  my $woah = "Woah, $result, that's awesome!";
13  
-  return $parent.process-query($woah, |%opts);
14  
-}
15  
-
14  t/lib/Example/Modifiers.pm6
... ...
@@ -0,0 +1,14 @@
  1
+class Example::Modifiers;
  2
+
  3
+has $.flower;
  4
+has $.tales;
  5
+
  6
+has %.handlers =
  7
+  'woah'   => 'woahize';
  8
+
  9
+method woahize ($query, *%opts) {
  10
+  my $result = $.tales.query($query);
  11
+  my $woah = "Woah, $result, that's awesome!";
  12
+  return $.tales.process-query($woah, |%opts);
  13
+}
  14
+

0 notes on commit 85d8307

Please sign in to comment.
Something went wrong with that request. Please try again.