File: 57-plp.t

package info (click to toggle)
libtext-micromason-perl 2.13-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 624 kB
  • ctags: 180
  • sloc: perl: 3,222; makefile: 23
file content (104 lines) | stat: -rw-r--r-- 2,038 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/perl -w

use strict;
use Test::More tests => 112;

use_ok 'Text::MicroMason';

ok my $m = Text::MicroMason->new( -PLP );

######################################################################

my $scr_hello = <<'ENDSCRIPT';
<: my $noun = 'World'; :>Hello <:= $noun :>!
How are ya?
ENDSCRIPT

my $res_hello = <<'ENDSCRIPT';
Hello World!
How are ya?
ENDSCRIPT

is $m->execute( text => $scr_hello), $res_hello;

is $m->compile( text => $scr_hello)->(), $res_hello;

ok my $scriptlet = $m->compile( text => $scr_hello);
is $scriptlet->(), $res_hello;
is $scriptlet->(), $res_hello;
is $scriptlet->(), $res_hello;

######################################################################

my $scr_bold = '<b><:= $ARGS{label} :></b>';
is $m->execute( text => $scr_bold, label=>'Foo'), '<b>Foo</b>';
is $m->compile( text => $scr_bold)->(label=>'Foo'), '<b>Foo</b>';

######################################################################

FLOW_CONTROL: {

    my $scr_rand = <<'ENDSCRIPT';
<: if ( int rand 2 ) { :>
  Hello World!
<: } else { :>
  Goodbye Cruel World!
<: } :>
ENDSCRIPT

  my $scriptlet = $m->compile(text => $scr_rand);

  for (0 .. 99) {
      like $scriptlet->(), qr/^\n  (Hello World!|Goodbye Cruel World!)\n$/;
  }
}

######################################################################

PERL_BLOCK: {
  
    my $scr_count = <<'ENDSCRIPT';
Counting...
<:
  foreach ( 1 .. 9 ) {
     $_out->( $_ )
  }
:>
Done!
ENDSCRIPT

    my $res_count = <<'ENDSCRIPT';
Counting...
123456789
Done!
ENDSCRIPT

    is $m->execute( text => $scr_count), $res_count;

}

SPANNING_PERL: {

    my $scr_count = <<'ENDSCRIPT';
<table><tr>
<: foreach ( 1 .. 9 ) { :>  <td><b><:= $_ :></b></td>
<: } :></tr></table>
ENDSCRIPT

    my $res_count = <<'ENDSCRIPT';
<table><tr>
  <td><b>1</b></td>
  <td><b>2</b></td>
  <td><b>3</b></td>
  <td><b>4</b></td>
  <td><b>5</b></td>
  <td><b>6</b></td>
  <td><b>7</b></td>
  <td><b>8</b></td>
  <td><b>9</b></td>
</tr></table>
ENDSCRIPT

    is $m->execute( text => $scr_count), $res_count;

}