File: Syntax.pm

package info (click to toggle)
libmason-perl 2.24-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 748 kB
  • sloc: perl: 4,882; makefile: 7
file content (249 lines) | stat: -rw-r--r-- 3,591 bytes parent folder | download | duplicates (3)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package Mason::t::Syntax;
$Mason::t::Syntax::VERSION = '2.24';
use Test::Class::Most parent => 'Mason::Test::Class';

sub test_replace : Tests {
    shift->test_comp(
        src => <<'EOF',
<BODY>
<% "Hello World!" %>
</BODY>
EOF
        expect => <<'EOF',
<BODY>
Hello World!
</BODY>
EOF
    );
}

sub test_percent : Tests {
    shift->test_comp(
        src => <<'EOF',
<BODY>
% my $message = "Hello World!";
<% $message %>
</BODY>
EOF
        expect => <<'EOF',
<BODY>
Hello World!
</BODY>
EOF
    );
}

sub test_fake_percent : Tests {
    shift->test_comp(
        src => <<'EOF',
some text, a %, and some text
EOF
        expect => <<'EOF',
some text, a %, and some text
EOF
    );
}

sub test_empty_percents : Tests {
    shift->test_comp(
        src => <<'EOF',
some text,
%
and some more
EOF
        expect => <<'EOF',
some text,
and some more
EOF
    );
}

sub test_empty_percents2 : Tests {
    shift->test_comp(
        src => <<'EOF',
some text,
%
% $m->print('foo, ');
% $m->print(undef);
and some more
EOF
        expect => <<'EOF',
some text,
foo, and some more
EOF
    );
}

# Deprecated syntax
#
sub test_double_percent : Tests {
    shift->test_comp(
        src => <<'EOF',
<%class>
my $i = 5;
</%class>

%% my $j = 0;
%% if ($i == 5) {
%%   $j = $i+1;
%% }
<% $.bar %>

<%method bar>
j = <% $j %>
</%method>

EOF
        expect => <<'EOF',
j = 6
EOF
    );
}

sub test_pure_perl : Tests {
    shift->test_comp(
        path   => '/pureperl.mp',
        src    => 'sub main { print "hello from main" }',
        expect => 'hello from main',
    );
}

# Deprecated syntax
#
sub test_args : Tests {
    my $self = shift;
    $self->add_comp(
        path => '/args.mc',
        src  => '
<%args>
a
b # comment

# comment
 c=>5
d => 6
e => "foo" # comment

f => (isa => "Num", default => 7)
g => (isa => "Num", default => 8) # comment
</%args>

a = <% $.a %>
b = <% $.b %>
c = <% $.c %>
d = <% $.d %>
e = <% $.e %>
f = <% $.f %>
g = <% $.g %>
',
    );
    $self->test_comp(
        src    => '<& /args.mc, a => 3, b => 4 &>',
        expect => '
a = 3
b = 4
c = 5
d = 6
e = foo
f = 7
g = 8
'
    );
}

sub test_multiline_comment : Tests {
    my $self = shift;

    $self->test_comp(
        src => '
hi<%
    # comment

    # another comment

%>bye
',
        expect => 'hibye',
    );
}

# Deprecated syntax
#
sub test_shared : Tests {
    shift->test_parse(
        src => '
<%shared>
$.foo  # a comment
 $.bar => "something"
$.baz => ( isa => "Num", default => 5 )
# another comment
</%shared>
',
        expect => [
            q/has 'foo' => (init_arg => undef/,
            q/has 'bar' => (init_arg => undef, default => "something"/,
            q/has 'baz' => (init_arg => undef,  isa => "Num", default => 5/
        ],
    );
}

sub test_dollar_dot : Tests {
    shift->test_comp(
        src => '
<%class>
has "bar" => (default => 4);
has "foo" => (default => 3);

</%class>

<% $self->show %>

<%method show>
foo = <% $.foo %>
bar = <% $.bar %>
</%method>

<%init>
$self->foo(5);
$self->bar(6);
</%init>
',
        expect => '
foo = 5
bar = 6
'
    );
}

sub test_dollar_m : Tests {
    my $self = shift;
    $self->test_comp(
        src => '
<%class>
method foo () { $m->print("foo\n") }
</%class>
<%method bar><%perl>$m->print("bar\n");</%perl></%method>
<% $.foo %>
<% $.bar %>
% $m->print("baz\n");
',
        expect => '
foo

bar

baz
',
    );
}

sub test_class_global : Tests {
    my $self = shift;

    $self->test_comp(
        src    => '<% ref($self) eq CLASS ? 1 : 0 %> <% ref($self) eq $CLASS ? 1 : 0 %>',
        expect => qr/1 1/,
    );
}

1;