File Coverage

blib/lib/CSS/Yamaantaka/Consts.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 18 100.0


line stmt bran cond sub pod time code
1             #-*- perl -*-
2             #-*- coding: us-ascii -*-
3              
4 34     34   488 use 5.005; # qr{} is required.
  34         166  
  34         4092  
5              
6             package CSS::Yamaantaka::Consts;
7              
8 34     34   174 use strict;
  34         62  
  34         3332  
9             #use warnings;
10              
11             # To be compatible with Perl 5.5 or earlier
12             my @OUR_VARS;
13              
14             BEGIN {
15 34     34   1791 @OUR_VARS = qw($NON_ASCII $UNICODE $ESCAPE $NMSTART $URL_SPECIAL_CHARS
16             $NMCHAR $STRING1 $STRING2 $COMMENT $IDENT $NAME $NUM $STRING
17             $URL_CHARS $HASH $URI
18             $UNIT $QUANTITY $LOOKBEHIND_NOT_LETTER $LOOKAHEAD_NOT_OPEN_BRACE
19             $VALID_AFTER_URI_CHARS $LOOKAHEAD_NOT_CLOSING_PAREN
20             $LOOKAHEAD_FOR_CLOSING_PAREN $POSSIBLY_NEGATIVE_QUANTITY
21             $FOUR_NOTATION_QUANTITY_RE $COLOR $FOUR_NOTATION_COLOR_RE
22             $BORDER_RADIUS_RE $CURSOR_EAST_RE $CURSOR_WEST_RE
23             $BG_HORIZONTAL_PERCENTAGE_RE $BG_HORIZONTAL_PERCENTAGE_X_RE
24             $LENGTH_UNIT $LOOKAHEAD_END_OF_ZERO $LENGTH $ZERO_LENGTH
25             $BG_HORIZONTAL_LENGTH_RE $BG_HORIZONTAL_LENGTH_X_RE
26             $CHARS_WITHIN_SELECTOR $BODY_DIRECTION_LTR_RE $BODY_DIRECTION_RTL_RE
27             $LEFT_RE $RIGHT_RE $LEFT_IN_URL_RE $RIGHT_IN_URL_RE
28             $LTR_IN_URL_RE $RTL_IN_URL_RE
29             $COMMENT_RE $NOFLIP_SINGLE_RE $NOFLIP_CLASS_RE
30             $BORDER_RADIUS_TOKENIZER_RE
31              
32             $SINGLE_BORDER_RADIUS_RE $SINGLE_BORDER_RADIUS_TOKENIZER_RE
33             $BOX_DIRECTIONS_RE $BOX_DIRECTION_IN_URL_RE
34             $LINE_RELATIVE_DIRECTION_RE $PROHIBITED_DIRECTION_RE
35             $CURSOR_DIRECTION_RE
36             $BG_QUANTITY_RE $BG_QUANTITY_XY_RE
37             );
38             }
39 34     34   203 use vars qw(@ISA @EXPORT $VERSION), @OUR_VARS;
  34         71  
  34         22207  
40 34     34   697 use Exporter;
  34         73  
  34         38386  
41             @ISA = qw(Exporter);
42             @EXPORT = @OUR_VARS;
43             $VERSION = '0.04_02';
44              
45             ## Constants
46              
47             # These are part of grammer taken from http://www.w3.org/TR/CSS21/grammar.html
48              
49             # nonascii [\240-\377]
50             # $NON_ASCII = '[\200-\377]';
51             # modified: handle characters beyond \377.
52             $NON_ASCII = "[^\\000-\\177]";
53              
54             # unicode \\{h}{1,6}(\r\n|[ \t\r\n\f])?
55             $UNICODE = "(?:(?:\\\\[0-9a-f]{1,6})(?:\\r\\n|[ \\t\\r\\n\\f])?)";
56              
57             # escape {unicode}|\\[^\r\n\f0-9a-f]
58             $ESCAPE = "(?:$UNICODE|\\\\[^\\r\\n\\f0-9a-f])";
59              
60             # nmstart [_a-z]|{nonascii}|{escape}
61             $NMSTART = "(?:[_a-z]|$NON_ASCII|$ESCAPE)";
62              
63             # nmchar [_a-z0-9-]|{nonascii}|{escape}
64             $NMCHAR = "(?:[_a-z0-9-]|$NON_ASCII|$ESCAPE)";
65              
66             # string1 \"([^\n\r\f\\"]|\\{nl}|{escape})*\"
67             $STRING1 = "\"(?:[^\"\\\\]|\\.)*\"";
68              
69             # string2 \'([^\n\r\f\\']|\\{nl}|{escape})*\'
70             $STRING2 = "\'(?:[^\'\\\\]|\\.)*\'";
71              
72             # comment \/\*[^*]*\*+([^/*][^*]*\*+)*\/
73             $COMMENT = '/\*[^*]*\*+([^/*][^*]*\*+)*/';
74              
75             # ident -?{nmstart}{nmchar}*
76             $IDENT = "-?$NMSTART$NMCHAR*";
77              
78             # name {nmchar}+
79             $NAME = "$NMCHAR+";
80              
81             # num [0-9]+|[0-9]*"."[0-9]+
82             $NUM = '(?:[0-9]*\.[0-9]+|[0-9]+)';
83              
84             # string {string1}|{string2}
85             $STRING = "(?:$STRING1|$STRING2)";
86              
87             # url ([!#$%&*-~]|{nonascii}|{escape})*
88             $URL_SPECIAL_CHARS = '[!#$%&*-~]';
89             $URL_CHARS = "(?:$URL_SPECIAL_CHARS|$NON_ASCII|$ESCAPE)*";
90              
91             # "#"{name} {return HASH;}
92             $HASH = "#$NAME";
93              
94             # "url("{w}{string}{w}")" {return URI;}
95             # "url("{w}{url}{w}")" {return URI;}
96             $URI = "url\\(\\s*(?:$STRING|$URL_CHARS)\\s*\\)";
97              
98             # These are regexps particular to this package.
99              
100             $UNIT = '(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)';
101             $QUANTITY = "$NUM(?:\\s*$UNIT|$IDENT)?";
102              
103             $LOOKBEHIND_NOT_LETTER = '(?
104             $LOOKAHEAD_NOT_OPEN_BRACE =
105             "(?!(?:$NMCHAR|~J~|\\s|#|\\:|\\.|\\,|\\+|>)*?\\{)";
106             $VALID_AFTER_URI_CHARS = '[\'\"]?\s*';
107             $LOOKAHEAD_NOT_CLOSING_PAREN = "(?!$URL_CHARS?$VALID_AFTER_URI_CHARS\\))";
108             $LOOKAHEAD_FOR_CLOSING_PAREN = "(?=$URL_CHARS?$VALID_AFTER_URI_CHARS\\))";
109              
110             $POSSIBLY_NEGATIVE_QUANTITY = "((?:-?$QUANTITY)|(?:inherit|auto))";
111             $FOUR_NOTATION_QUANTITY_RE =
112             qr<$POSSIBLY_NEGATIVE_QUANTITY\s+$POSSIBLY_NEGATIVE_QUANTITY\s+$POSSIBLY_NEGATIVE_QUANTITY\s+$POSSIBLY_NEGATIVE_QUANTITY>i;
113              
114             # $COLOR = "($NAME|$HASH);
115             # modified: added "rgb(...)".
116             my $COLOR_SCHEME = '(?:rgb|rgba|hsl|hsla)';
117             $COLOR = "($COLOR_SCHEME\\([^\)]+\\)|$NAME|$HASH)";
118             $FOUR_NOTATION_COLOR_RE =
119             qr<(-color\s*:\s*)$COLOR\s$COLOR\s$COLOR\s($COLOR)>i;
120              
121             $BORDER_RADIUS_RE =
122             qr<((?:$IDENT)?)border-radius(\s*:\s*)(?:$POSSIBLY_NEGATIVE_QUANTITY\s+)?(?:$POSSIBLY_NEGATIVE_QUANTITY\s+)?(?:$POSSIBLY_NEGATIVE_QUANTITY\s+)?(?:$POSSIBLY_NEGATIVE_QUANTITY)(?:\s*/\s*(?:$POSSIBLY_NEGATIVE_QUANTITY\s+)?(?:$POSSIBLY_NEGATIVE_QUANTITY\s+)?(?:$POSSIBLY_NEGATIVE_QUANTITY\s+)?(?:$POSSIBLY_NEGATIVE_QUANTITY))?>i;
123              
124             # Not used: use $CURSOR_DIRECTION_RE
125             $CURSOR_EAST_RE = qr<$LOOKBEHIND_NOT_LETTER([ns]?)e-resize>;
126             # ditto
127             $CURSOR_WEST_RE = qr<$LOOKBEHIND_NOT_LETTER([ns]?)w-resize>;
128              
129             # Term of background property. Gradirents may not be included because they
130             # will have been tokenized.
131             my $BG_TERM = "(?:$URI|$STRING|$COLOR_SCHEME\\([^\)]+\\)|[^\\s;\}]+)";
132              
133             #$BG_HORIZONTAL_PERCENTAGE_RE =
134             # qr;
135             # modified: fixed cssjanus Issue #20.
136             # Not used: use $BG_QUANTITY_RE.
137             $BG_HORIZONTAL_PERCENTAGE_RE =
138             qr;
139             # Not used: use $BG_QUANTITY_XY_RE.
140             $BG_HORIZONTAL_PERCENTAGE_X_RE = qr;
141              
142             $LENGTH_UNIT = '(?:em|ex|px|cm|mm|in|pt|pc)';
143             $LOOKAHEAD_END_OF_ZERO = '(?![0-9]|\s*%)';
144             $LENGTH = "(?:-?$NUM(?:\\s*$LENGTH_UNIT)|0+$LOOKAHEAD_END_OF_ZERO)";
145             $ZERO_LENGTH = "(?:-?0+(?:\\s*$LENGTH_UNIT)|0+$LOOKAHEAD_END_OF_ZERO)\$";
146              
147             # $BG_HORIZONTAL_LENGTH_RE =
148             # qr;
149             # modified: fixed cssjanus Issue #20.
150             # Not used: use $BG_QUANTITY_RE.
151             $BG_HORIZONTAL_LENGTH_RE =
152             qr;
153             # Not used: use $BG_QUANTITY_XY_RE.
154             $BG_HORIZONTAL_LENGTH_X_RE = qr;
155              
156             $CHARS_WITHIN_SELECTOR = '[^\}]*?';
157             $BODY_DIRECTION_LTR_RE =
158             qr<(body\s*{\s*)($CHARS_WITHIN_SELECTOR)(direction\s*:\s*)(ltr)>i;
159             $BODY_DIRECTION_RTL_RE =
160             qr<(body\s*{\s*)($CHARS_WITHIN_SELECTOR)(direction\s*:\s*)(rtl)>i;
161              
162             # Not used: use $BOX_DIRECTION_RE.
163             $LEFT_RE =
164             qr<$LOOKBEHIND_NOT_LETTER((?:top|bottom)?)(left)$LOOKAHEAD_NOT_CLOSING_PAREN$LOOKAHEAD_NOT_OPEN_BRACE>i;
165             # ditto
166             $RIGHT_RE =
167             qr<$LOOKBEHIND_NOT_LETTER((?:top|bottom)?)(right)$LOOKAHEAD_NOT_CLOSING_PAREN$LOOKAHEAD_NOT_OPEN_BRACE>i;
168             # Not used: use $BOX_DIRECTION_IN_URL_RE.
169             $LEFT_IN_URL_RE =
170             qr<$LOOKBEHIND_NOT_LETTER(left)$LOOKAHEAD_FOR_CLOSING_PAREN>i;
171             # ditto
172             $RIGHT_IN_URL_RE =
173             qr<$LOOKBEHIND_NOT_LETTER(right)$LOOKAHEAD_FOR_CLOSING_PAREN>i;
174             $LTR_IN_URL_RE = qr<$LOOKBEHIND_NOT_LETTER(ltr)$LOOKAHEAD_FOR_CLOSING_PAREN>i;
175             $RTL_IN_URL_RE = qr<$LOOKBEHIND_NOT_LETTER(rtl)$LOOKAHEAD_FOR_CLOSING_PAREN>i;
176              
177             $COMMENT_RE = qr<($COMMENT)>i;
178             $NOFLIP_SINGLE_RE =
179             qr<(/\*\s*\@noflip\s*\*/$LOOKAHEAD_NOT_OPEN_BRACE[^;}]+;?)>i;
180             $NOFLIP_CLASS_RE = qr<(/\*\s*\@noflip\s*\*/$CHARS_WITHIN_SELECTOR})>i;
181             $BORDER_RADIUS_TOKENIZER_RE = qr<((?:$IDENT)?border-radius\s*:[^;}]+;?)>i;
182              
183             ## Regexps added by CSS-Flip package.
184              
185             # border-radius with single position.
186             $SINGLE_BORDER_RADIUS_RE =
187             qr<((?:$IDENT)?)border-(?:(top|bottom)-(left|right)-radius|radius-(top|bottom)(left|right))(\s*:\s*)(?:$POSSIBLY_NEGATIVE_QUANTITY\s+)?(?:$POSSIBLY_NEGATIVE_QUANTITY)>i;
188             $SINGLE_BORDER_RADIUS_TOKENIZER_RE =
189             qr<((?:$IDENT)?border-(?:(top|bottom)-(left|right)-radius|radius-(top|bottom)(left|right))\s*:[^;}]+;?)>i;
190             # box directions.
191             $BOX_DIRECTIONS_RE =
192             qr<$LOOKBEHIND_NOT_LETTER(?:(top|right|bottom|left|center)(\s+|-)(top|right|bottom|left|center)|(top|right|bottom|left))$LOOKAHEAD_NOT_CLOSING_PAREN$LOOKAHEAD_NOT_OPEN_BRACE>i;
193             # box directions in URL.
194             $BOX_DIRECTION_IN_URL_RE =
195             qr<$LOOKBEHIND_NOT_LETTER(top|right|bottom|left)$LOOKAHEAD_FOR_CLOSING_PAREN>i;
196             # Reversed only by ltr <-> rtl transformation.
197             $LINE_RELATIVE_DIRECTION_RE =
198             qr<((?:(?:$IDENT)?text-align(?:-last)?|float|clear|vertical-align)\s*:\s*[^;}]*;?)>;
199             # Won't reverse left/right.
200             $PROHIBITED_DIRECTION_RE =
201             qr<((?:ruby-position|ruby-align|text-emphasis-position|text-underline-position)\s*:\s*[^;}]*;?)>;
202             # cursor positions.
203             $CURSOR_DIRECTION_RE =
204             qr<$LOOKBEHIND_NOT_LETTER(nesw|nwse|[ns][we]|[nswe])-resize>;
205             # background position
206             $BG_QUANTITY_RE =
207             qr;
208             $BG_QUANTITY_XY_RE = qr;
209              
210             1;