blib/lib/BBCode/Tag/CODE.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 28 | 30 | 93.3 |
branch | 4 | 6 | 66.6 |
condition | n/a | ||
subroutine | 9 | 10 | 90.0 |
pod | 6 | 6 | 100.0 |
total | 47 | 52 | 90.3 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | # $Id: CODE.pm 284 2006-12-01 07:51:49Z chronos $ | ||||||
2 | package BBCode::Tag::CODE; | ||||||
3 | 2 | 2 | 12 | use base qw(BBCode::Tag::Block); | |||
2 | 4 | ||||||
2 | 197 | ||||||
4 | 2 | 2 | 11 | use BBCode::Util qw(encodeHTML multilineText); | |||
2 | 4 | ||||||
2 | 117 | ||||||
5 | 2 | 2 | 10 | use strict; | |||
2 | 4 | ||||||
2 | 69 | ||||||
6 | 2 | 2 | 11 | use warnings; | |||
2 | 3 | ||||||
2 | 1100 | ||||||
7 | our $VERSION = '0.34'; | ||||||
8 | |||||||
9 | sub BodyPermitted($):method { | ||||||
10 | 8 | 8 | 1 | 34 | return 1; | ||
11 | } | ||||||
12 | |||||||
13 | sub BodyTags($):method { | ||||||
14 | 6 | 6 | 1 | 23 | return qw(:TEXT URL EMAIL); | ||
15 | } | ||||||
16 | |||||||
17 | sub NamedParams($):method { | ||||||
18 | 4 | 4 | 1 | 15 | return qw(LANG); | ||
19 | } | ||||||
20 | |||||||
21 | sub RequiredParams($):method { | ||||||
22 | 0 | 0 | 1 | 0 | return (); | ||
23 | } | ||||||
24 | |||||||
25 | sub validateParam($$$):method { | ||||||
26 | 2 | 2 | 1 | 7 | my($this,$param,$val) = @_; | ||
27 | 2 | 50 | 14 | if($param eq 'LANG') { | |||
28 | 2 | 6 | $val =~ s/_/-/g; | ||||
29 | 2 | 100 | 14 | if($val =~ /^ \w+ (?: - \w+ )* $/x) { | |||
30 | 1 | 5 | return $val; | ||||
31 | } else { | ||||||
32 | 1 | 45 | die qq(Invalid value "$val" for [CODE LANG]); | ||||
33 | } | ||||||
34 | } | ||||||
35 | 0 | 0 | return $this->SUPER::validateParam($param,$val); | ||||
36 | } | ||||||
37 | |||||||
38 | sub toHTML($):method { | ||||||
39 | 1 | 1 | 1 | 3 | my $this = shift; | ||
40 | 1 | 11 | my $pfx = $this->parser->css_prefix; | ||||
41 | |||||||
42 | 1 | 5 | my $lang = $this->param('LANG'); | ||||
43 | 1 | 9 | my $body = $this->bodyHTML; | ||||
44 | 1 | 6 | $body =~ s# $##mg; |
||||
45 | 1 | 4 | $body =~ s# #\n#g; |
||||
46 | 1 | 50 | 11 | return multilineText | |||
47 | qq( \n), |
||||||
48 | qq( ), (defined $lang ? encodeHTML(ucfirst "$lang ") : ""), qq(Code: \n), |
||||||
49 | qq(\n), |
||||||
50 | qq($body\n), | ||||||
51 | qq(\n), | ||||||
52 | qq(\n); | ||||||
53 | } | ||||||
54 | |||||||
55 | 1; |