blib/lib/Perl6/Pod/FormattingCode/E.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 18 | 44 | 40.9 |
branch | 0 | 10 | 0.0 |
condition | n/a | ||
subroutine | 6 | 9 | 66.6 |
pod | 2 | 2 | 100.0 |
total | 26 | 65 | 40.0 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | #=============================================================================== | ||||||
2 | # | ||||||
3 | # DESCRIPTION: Implement E (Entities) | ||||||
4 | # | ||||||
5 | # AUTHOR: Aliaksandr P. Zahatski, |
||||||
6 | #=============================================================================== | ||||||
7 | package Perl6::Pod::FormattingCode::E; | ||||||
8 | 3 | 3 | 14 | use warnings; | |||
3 | 5 | ||||||
3 | 86 | ||||||
9 | 3 | 3 | 16 | use strict; | |||
3 | 4 | ||||||
3 | 58 | ||||||
10 | 3 | 3 | 15 | use Data::Dumper; | |||
3 | 4 | ||||||
3 | 135 | ||||||
11 | 3 | 3 | 16 | use Perl6::Pod::FormattingCode; | |||
3 | 6 | ||||||
3 | 61 | ||||||
12 | 3 | 3 | 13 | use base 'Perl6::Pod::FormattingCode'; | |||
3 | 6 | ||||||
3 | 944 | ||||||
13 | our $VERSION = '0.01'; | ||||||
14 | |||||||
15 | =pod | ||||||
16 | |||||||
17 | =head1 NAME | ||||||
18 | |||||||
19 | Perl6::Pod::FormattingCode::E - include named Unicode or XHTML entities | ||||||
20 | |||||||
21 | =head1 SYNOPSIS | ||||||
22 | |||||||
23 | Perl 6 makes considerable use of E<171> and E<187>. | ||||||
24 | |||||||
25 | C<1E |
||||||
26 | |||||||
27 | my $label-area-width = 1 + [max] @scoresE |
||||||
28 | |||||||
29 | |||||||
30 | =head1 DESCRIPTION | ||||||
31 | |||||||
32 | If the contents of the C |
||||||
33 | |||||||
34 | Perl 6 makes considerable use of E<171> and E<187>. | ||||||
35 | |||||||
36 | You can also use explicit binary, octal, decimal, or hexadecimal numbers (using the Perl 6 notations for explicitly based numbers): | ||||||
37 | |||||||
38 | Perl 6 makes considerable use of E<0b10101011> and E<0b10111011>. | ||||||
39 | Perl 6 makes considerable use of E<0o253> and E<0o273>. | ||||||
40 | Perl 6 makes considerable use of E<0d171> and E<0d187>. | ||||||
41 | Perl 6 makes considerable use of E<0xAB> and E<0xBB>. | ||||||
42 | |||||||
43 | If the contents are not a number, they are interpreted as a Unicode character name (which is always upper-case), or else as an XHTML entity. For example: | ||||||
44 | |||||||
45 | Perl 6 makes considerable use of E |
||||||
46 | and E |
||||||
47 | |||||||
48 | or, equivalently: | ||||||
49 | |||||||
50 | Perl 6 makes considerable use of E |
||||||
51 | |||||||
52 | Multiple consecutive entities can be specified in a single C |
||||||
53 | |||||||
54 | Perl 6 makes considerable use of E |
||||||
55 | |||||||
56 | =cut | ||||||
57 | |||||||
58 | =head2 to_xhtml | ||||||
59 | |||||||
60 | E |
||||||
61 | |||||||
62 | Render to | ||||||
63 | |||||||
64 | < | ||||||
65 | |||||||
66 | =cut | ||||||
67 | my %line_break = (NEL=>1); | ||||||
68 | |||||||
69 | sub to_xhtml { | ||||||
70 | 0 | 0 | 1 | my ( $self, $to ) = @_; | |||
71 | 0 | my $line = $self->childs->[0]; | |||||
72 | #split by ; | ||||||
73 | [ | ||||||
74 | map { | ||||||
75 | 0 | s/^\s+//; | |||||
0 | |||||||
76 | 0 | s/\s+$//; | |||||
77 | 0 | 0 | if ( exists $line_break{$_} ) { | ||||
78 | 0 | $to->w->raw(' ') |
|||||
79 | } else { | ||||||
80 | 0 | $to->w->raw( _to_xhtml_entity($_) ) | |||||
81 | } | ||||||
82 | } | ||||||
83 | split( /\s*;\s*/, $line ) | ||||||
84 | ]; | ||||||
85 | } | ||||||
86 | sub _to_xhtml_entity { | ||||||
87 | 0 | 0 | my $str = shift; | ||||
88 | 0 | 0 | if ( $str !~ /^\d/ ) { | ||||
89 | 3 | 3 | 19753 | use charnames ':full'; | |||
3 | 198948 | ||||||
3 | 24 | ||||||
90 | 0 | my $ord = charnames::vianame($str); | |||||
91 | 0 | 0 | return sprintf( '%d;', $ord ) if defined $ord; | ||||
92 | 0 | return qq{&$str;}; | |||||
93 | } | ||||||
94 | # Otherwise, it's the numeric codepoint in some base... | ||||||
95 | else { | ||||||
96 | # Convert Perl 6 octals and decimals to Perl 5 notation... | ||||||
97 | 0 | 0 | if ($str !~ s{\A 0o}{0}xms) { # Convert octal | ||||
98 | 0 | $str =~ s{\A 0d}{}xms; # Convert explicit decimal | |||||
99 | 0 | $str =~ s{\A 0+ (?=\d)}{}xms; # Convert implicit decimal | |||||
100 | } | ||||||
101 | |||||||
102 | # Then return the XHTML numeric code... | ||||||
103 | 0 | return sprintf '%d;', eval $str; | |||||
104 | } | ||||||
105 | |||||||
106 | 0 | die "Unsupported identity $_ in E<>"; | |||||
107 | } | ||||||
108 | |||||||
109 | =head2 to_docbook | ||||||
110 | |||||||
111 | E |
||||||
112 | |||||||
113 | Render to | ||||||
114 | |||||||
115 | < | ||||||
116 | |||||||
117 | =cut | ||||||
118 | |||||||
119 | sub to_docbook { | ||||||
120 | 0 | 0 | 1 | my ( $self, $to ) = @_; | |||
121 | 0 | my $line = $self->childs->[0]; | |||||
122 | #split by ; | ||||||
123 | [ | ||||||
124 | map { | ||||||
125 | 0 | s/^\s+//; | |||||
0 | |||||||
126 | 0 | s/\s+$//; | |||||
127 | # not exists in docbook |
||||||
128 | 0 | 0 | if (exists $line_break{$_} ) {()} else { | ||||
0 | |||||||
129 | 0 | $to->w->raw( _to_xhtml_entity($_) ) | |||||
130 | } | ||||||
131 | } | ||||||
132 | split( /\s*;\s*/, $line ) | ||||||
133 | ]; | ||||||
134 | } | ||||||
135 | |||||||
136 | 1; | ||||||
137 | __END__ |