File Coverage

blib/lib/CSS/Janus/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 25     25   402 use 5.005; # qr{} is required.
  25         85  
  25         1570  
5              
6             package CSS::Janus::Consts;
7              
8 25     25   140 use strict;
  25         57  
  25         2201  
9             #use warnings;
10              
11             # To be compatible with Perl 5.5 or earlier
12             my @OUR_VARS;
13              
14             BEGIN {
15 25     25   1154 @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 25     25   146 use vars qw(@ISA @EXPORT $VERSION), @OUR_VARS;
  25         61  
  25         12722  
33 25     25   142 use Exporter;
  25         40  
  25         23269  
34             @ISA = qw(Exporter);
35             @EXPORT = @OUR_VARS;
36             $VERSION = '0.01';
37              
38             ## Constants
39              
40             # These are part of grammer taken from http://www.w3.org/TR/CSS21/grammar.html
41              
42             # nonascii [\240-\377]
43             # $NON_ASCII = '[\200-\377]';
44             # modified: handle characters beyond \377.
45             $NON_ASCII = "[^\\000-\\177]";
46              
47             # unicode \\{h}{1,6}(\r\n|[ \t\r\n\f])?
48             $UNICODE = "(?:(?:\\\\[0-9a-f]{1,6})(?:\\r\\n|[ \\t\\r\\n\\f])?)";
49              
50             # escape {unicode}|\\[^\r\n\f0-9a-f]
51             $ESCAPE = "(?:$UNICODE|\\\\[^\\r\\n\\f0-9a-f])";
52              
53             # nmstart [_a-z]|{nonascii}|{escape}
54             $NMSTART = "(?:[_a-z]|$NON_ASCII|$ESCAPE)";
55              
56             # nmchar [_a-z0-9-]|{nonascii}|{escape}
57             $NMCHAR = "(?:[_a-z0-9-]|$NON_ASCII|$ESCAPE)";
58              
59             # string1 \"([^\n\r\f\\"]|\\{nl}|{escape})*\"
60             $STRING1 = "\"(?:[^\"\\\\]|\\.)*\"";
61              
62             # string2 \'([^\n\r\f\\']|\\{nl}|{escape})*\'
63             $STRING2 = "\'(?:[^\'\\\\]|\\.)*\'";
64              
65             # comment \/\*[^*]*\*+([^/*][^*]*\*+)*\/
66             $COMMENT = '/\*[^*]*\*+([^/*][^*]*\*+)*/';
67              
68             # ident -?{nmstart}{nmchar}*
69             $IDENT = "-?$NMSTART$NMCHAR*";
70              
71             # name {nmchar}+
72             $NAME = "$NMCHAR+";
73              
74             # num [0-9]+|[0-9]*"."[0-9]+
75             $NUM = '(?:[0-9]*\.[0-9]+|[0-9]+)';
76              
77             # string {string1}|{string2}
78             $STRING = "(?:$STRING1|$STRING2)";
79              
80             # url ([!#$%&*-~]|{nonascii}|{escape})*
81             $URL_SPECIAL_CHARS = '[!#$%&*-~]';
82             $URL_CHARS = "(?:$URL_SPECIAL_CHARS|$NON_ASCII|$ESCAPE)*";
83              
84             # "#"{name} {return HASH;}
85             $HASH = "#$NAME";
86              
87             # "url("{w}{string}{w}")" {return URI;}
88             # "url("{w}{url}{w}")" {return URI;}
89             $URI = "url\\(\\s*(?:$STRING|$URL_CHARS)\\s*\\)";
90              
91             # These are regexps particular to this package.
92              
93             $UNIT = '(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)';
94             $QUANTITY = "$NUM(?:\\s*$UNIT|$IDENT)?";
95              
96             $LOOKBEHIND_NOT_LETTER = '(?
97             $LOOKAHEAD_NOT_OPEN_BRACE =
98             "(?!(?:$NMCHAR|~J~|\\s|#|\\:|\\.|\\,|\\+|>)*?\\{)";
99             $VALID_AFTER_URI_CHARS = '[\'\"]?\s*';
100             $LOOKAHEAD_NOT_CLOSING_PAREN = "(?!$URL_CHARS?$VALID_AFTER_URI_CHARS\\))";
101             $LOOKAHEAD_FOR_CLOSING_PAREN = "(?=$URL_CHARS?$VALID_AFTER_URI_CHARS\\))";
102              
103             $POSSIBLY_NEGATIVE_QUANTITY = "((?:-?$QUANTITY)|(?:inherit|auto))";
104             $FOUR_NOTATION_QUANTITY_RE =
105             qr<$POSSIBLY_NEGATIVE_QUANTITY\s+$POSSIBLY_NEGATIVE_QUANTITY\s+$POSSIBLY_NEGATIVE_QUANTITY\s+$POSSIBLY_NEGATIVE_QUANTITY>i;
106              
107             # $COLOR = "($NAME|$HASH);
108             # modified: added "rgb(...)".
109             my $COLOR_SCHEME = '(?:rgb|rgba|hsl|hsla)';
110             $COLOR = "($COLOR_SCHEME\\([^\)]+\\)|$NAME|$HASH)";
111             $FOUR_NOTATION_COLOR_RE =
112             qr<(-color\s*:\s*)$COLOR\s$COLOR\s$COLOR\s($COLOR)>i;
113              
114             $BORDER_RADIUS_RE =
115             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;
116              
117             $CURSOR_EAST_RE = qr<$LOOKBEHIND_NOT_LETTER([ns]?)e-resize>;
118             $CURSOR_WEST_RE = qr<$LOOKBEHIND_NOT_LETTER([ns]?)w-resize>;
119              
120             # Term of background property. Gradirents may not be included because they
121             # will have been tokenized.
122             my $BG_TERM = "(?:$URI|$STRING|$COLOR_SCHEME\\([^\)]+\\)|[^\\s;\}]+)";
123              
124             #$BG_HORIZONTAL_PERCENTAGE_RE =
125             # qr;
126             # modified: fixed cssjanus Issue #20.
127             $BG_HORIZONTAL_PERCENTAGE_RE =
128             qr;
129             $BG_HORIZONTAL_PERCENTAGE_X_RE = qr;
130              
131             $LENGTH_UNIT = '(?:em|ex|px|cm|mm|in|pt|pc)';
132             $LOOKAHEAD_END_OF_ZERO = '(?![0-9]|\s*%)';
133             $LENGTH = "(?:-?$NUM(?:\\s*$LENGTH_UNIT)|0+$LOOKAHEAD_END_OF_ZERO)";
134             $ZERO_LENGTH = "(?:-?0+(?:\\s*$LENGTH_UNIT)|0+$LOOKAHEAD_END_OF_ZERO)\$";
135              
136             # $BG_HORIZONTAL_LENGTH_RE =
137             # qr;
138             # modified: fixed cssjanus Issue #20.
139             $BG_HORIZONTAL_LENGTH_RE =
140             qr;
141             $BG_HORIZONTAL_LENGTH_X_RE = qr;
142              
143             $CHARS_WITHIN_SELECTOR = '[^\}]*?';
144             $BODY_DIRECTION_LTR_RE =
145             qr<(body\s*{\s*)($CHARS_WITHIN_SELECTOR)(direction\s*:\s*)(ltr)>i;
146             $BODY_DIRECTION_RTL_RE =
147             qr<(body\s*{\s*)($CHARS_WITHIN_SELECTOR)(direction\s*:\s*)(rtl)>i;
148              
149             $LEFT_RE =
150             qr<$LOOKBEHIND_NOT_LETTER((?:top|bottom)?)(left)$LOOKAHEAD_NOT_CLOSING_PAREN$LOOKAHEAD_NOT_OPEN_BRACE>i;
151             $RIGHT_RE =
152             qr<$LOOKBEHIND_NOT_LETTER((?:top|bottom)?)(right)$LOOKAHEAD_NOT_CLOSING_PAREN$LOOKAHEAD_NOT_OPEN_BRACE>i;
153             $LEFT_IN_URL_RE =
154             qr<$LOOKBEHIND_NOT_LETTER(left)$LOOKAHEAD_FOR_CLOSING_PAREN>i;
155             $RIGHT_IN_URL_RE =
156             qr<$LOOKBEHIND_NOT_LETTER(right)$LOOKAHEAD_FOR_CLOSING_PAREN>i;
157             $LTR_IN_URL_RE = qr<$LOOKBEHIND_NOT_LETTER(ltr)$LOOKAHEAD_FOR_CLOSING_PAREN>i;
158             $RTL_IN_URL_RE = qr<$LOOKBEHIND_NOT_LETTER(rtl)$LOOKAHEAD_FOR_CLOSING_PAREN>i;
159              
160             $COMMENT_RE = qr<($COMMENT)>i;
161             $NOFLIP_SINGLE_RE =
162             qr<(/\*\s*\@noflip\s*\*/$LOOKAHEAD_NOT_OPEN_BRACE[^;}]+;?)>i;
163             $NOFLIP_CLASS_RE = qr<(/\*\s*\@noflip\s*\*/$CHARS_WITHIN_SELECTOR})>i;
164             $BORDER_RADIUS_TOKENIZER_RE = qr<((?:$IDENT)?border-radius\s*:[^;}]+;?)>i;
165              
166             1;