.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Mojo::DOM::CSS 3pm" .TH Mojo::DOM::CSS 3pm "2014-08-19" "perl v5.20.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojo::DOM::CSS \- CSS selector engine .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::DOM::CSS; \& \& # Select elements from DOM tree \& my $css = Mojo::DOM::CSS\->new(tree => $tree); \& my $elements = $css\->select(\*(Aqh1, h2, h3\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::DOM::CSS is the \s-1CSS\s0 selector engine used by Mojo::DOM and based on Selectors Level 3 . .SH "SELECTORS" .IX Header "SELECTORS" All \s-1CSS\s0 selectors that make sense for a standalone parser are supported. .SS "*" .IX Subsection "*" Any element. .PP .Vb 1 \& my $all = $css\->select(\*(Aq*\*(Aq); .Ve .SS "E" .IX Subsection "E" An element of type \f(CW\*(C`E\*(C'\fR. .PP .Vb 1 \& my $title = $css\->select(\*(Aqtitle\*(Aq); .Ve .SS "E[foo]" .IX Subsection "E[foo]" An \f(CW\*(C`E\*(C'\fR element with a \f(CW\*(C`foo\*(C'\fR attribute. .PP .Vb 1 \& my $links = $css\->select(\*(Aqa[href]\*(Aq); .Ve .ie n .SS "E[foo=""bar""]" .el .SS "E[foo=``bar'']" .IX Subsection "E[foo=bar]" An \f(CW\*(C`E\*(C'\fR element whose \f(CW\*(C`foo\*(C'\fR attribute value is exactly equal to \f(CW\*(C`bar\*(C'\fR. .PP .Vb 1 \& my $fields = $css\->select(\*(Aqinput[name="foo"]\*(Aq); .Ve .ie n .SS "E[foo~=""bar""]" .el .SS "E[foo~=``bar'']" .IX Subsection "E[foo~=bar]" An \f(CW\*(C`E\*(C'\fR element whose \f(CW\*(C`foo\*(C'\fR attribute value is a list of whitespace-separated values, one of which is exactly equal to \f(CW\*(C`bar\*(C'\fR. .PP .Vb 1 \& my $fields = $css\->select(\*(Aqinput[name~="foo"]\*(Aq); .Ve .ie n .SS "E[foo^=""bar""]" .el .SS "E[foo^=``bar'']" .IX Subsection "E[foo^=bar]" An \f(CW\*(C`E\*(C'\fR element whose \f(CW\*(C`foo\*(C'\fR attribute value begins exactly with the string \&\f(CW\*(C`bar\*(C'\fR. .PP .Vb 1 \& my $fields = $css\->select(\*(Aqinput[name^="f"]\*(Aq); .Ve .ie n .SS "E[foo$=""bar""]" .el .SS "E[foo$=``bar'']" .IX Subsection "E[foo$=bar]" An \f(CW\*(C`E\*(C'\fR element whose \f(CW\*(C`foo\*(C'\fR attribute value ends exactly with the string \&\f(CW\*(C`bar\*(C'\fR. .PP .Vb 1 \& my $fields = $css\->select(\*(Aqinput[name$="o"]\*(Aq); .Ve .ie n .SS "E[foo*=""bar""]" .el .SS "E[foo*=``bar'']" .IX Subsection "E[foo*=bar]" An \f(CW\*(C`E\*(C'\fR element whose \f(CW\*(C`foo\*(C'\fR attribute value contains the substring \f(CW\*(C`bar\*(C'\fR. .PP .Vb 1 \& my $fields = $css\->select(\*(Aqinput[name*="fo"]\*(Aq); .Ve .SS "E:root" .IX Subsection "E:root" An \f(CW\*(C`E\*(C'\fR element, root of the document. .PP .Vb 1 \& my $root = $css\->select(\*(Aq:root\*(Aq); .Ve .SS "E:checked" .IX Subsection "E:checked" A user interface element \f(CW\*(C`E\*(C'\fR which is checked (for instance a radio-button or checkbox). .PP .Vb 1 \& my $input = $css\->select(\*(Aq:checked\*(Aq); .Ve .SS "E:empty" .IX Subsection "E:empty" An \f(CW\*(C`E\*(C'\fR element that has no children (including text nodes). .PP .Vb 1 \& my $empty = $css\->select(\*(Aq:empty\*(Aq); .Ve .SS "E:nth\-child(n)" .IX Subsection "E:nth-child(n)" An \f(CW\*(C`E\*(C'\fR element, the \f(CW\*(C`n\-th\*(C'\fR child of its parent. .PP .Vb 4 \& my $third = $css\->select(\*(Aqdiv:nth\-child(3)\*(Aq); \& my $odd = $css\->select(\*(Aqdiv:nth\-child(odd)\*(Aq); \& my $even = $css\->select(\*(Aqdiv:nth\-child(even)\*(Aq); \& my $top3 = $css\->select(\*(Aqdiv:nth\-child(\-n+3)\*(Aq); .Ve .SS "E:nth\-last\-child(n)" .IX Subsection "E:nth-last-child(n)" An \f(CW\*(C`E\*(C'\fR element, the \f(CW\*(C`n\-th\*(C'\fR child of its parent, counting from the last one. .PP .Vb 4 \& my $third = $css\->select(\*(Aqdiv:nth\-last\-child(3)\*(Aq); \& my $odd = $css\->select(\*(Aqdiv:nth\-last\-child(odd)\*(Aq); \& my $even = $css\->select(\*(Aqdiv:nth\-last\-child(even)\*(Aq); \& my $bottom3 = $css\->select(\*(Aqdiv:nth\-last\-child(\-n+3)\*(Aq); .Ve .SS "E:nth\-of\-type(n)" .IX Subsection "E:nth-of-type(n)" An \f(CW\*(C`E\*(C'\fR element, the \f(CW\*(C`n\-th\*(C'\fR sibling of its type. .PP .Vb 4 \& my $third = $css\->select(\*(Aqdiv:nth\-of\-type(3)\*(Aq); \& my $odd = $css\->select(\*(Aqdiv:nth\-of\-type(odd)\*(Aq); \& my $even = $css\->select(\*(Aqdiv:nth\-of\-type(even)\*(Aq); \& my $top3 = $css\->select(\*(Aqdiv:nth\-of\-type(\-n+3)\*(Aq); .Ve .SS "E:nth\-last\-of\-type(n)" .IX Subsection "E:nth-last-of-type(n)" An \f(CW\*(C`E\*(C'\fR element, the \f(CW\*(C`n\-th\*(C'\fR sibling of its type, counting from the last one. .PP .Vb 4 \& my $third = $css\->select(\*(Aqdiv:nth\-last\-of\-type(3)\*(Aq); \& my $odd = $css\->select(\*(Aqdiv:nth\-last\-of\-type(odd)\*(Aq); \& my $even = $css\->select(\*(Aqdiv:nth\-last\-of\-type(even)\*(Aq); \& my $bottom3 = $css\->select(\*(Aqdiv:nth\-last\-of\-type(\-n+3)\*(Aq); .Ve .SS "E:first\-child" .IX Subsection "E:first-child" An \f(CW\*(C`E\*(C'\fR element, first child of its parent. .PP .Vb 1 \& my $first = $css\->select(\*(Aqdiv p:first\-child\*(Aq); .Ve .SS "E:last\-child" .IX Subsection "E:last-child" An \f(CW\*(C`E\*(C'\fR element, last child of its parent. .PP .Vb 1 \& my $last = $css\->select(\*(Aqdiv p:last\-child\*(Aq); .Ve .SS "E:first\-of\-type" .IX Subsection "E:first-of-type" An \f(CW\*(C`E\*(C'\fR element, first sibling of its type. .PP .Vb 1 \& my $first = $css\->select(\*(Aqdiv p:first\-of\-type\*(Aq); .Ve .SS "E:last\-of\-type" .IX Subsection "E:last-of-type" An \f(CW\*(C`E\*(C'\fR element, last sibling of its type. .PP .Vb 1 \& my $last = $css\->select(\*(Aqdiv p:last\-of\-type\*(Aq); .Ve .SS "E:only\-child" .IX Subsection "E:only-child" An \f(CW\*(C`E\*(C'\fR element, only child of its parent. .PP .Vb 1 \& my $lonely = $css\->select(\*(Aqdiv p:only\-child\*(Aq); .Ve .SS "E:only\-of\-type" .IX Subsection "E:only-of-type" An \f(CW\*(C`E\*(C'\fR element, only sibling of its type. .PP .Vb 1 \& my $lonely = $css\->select(\*(Aqdiv p:only\-of\-type\*(Aq); .Ve .SS "E.warning" .IX Subsection "E.warning" An \f(CW\*(C`E\*(C'\fR element whose class is \*(L"warning\*(R". .PP .Vb 1 \& my $warning = $css\->select(\*(Aqdiv.warning\*(Aq); .Ve .SS "E#myid" .IX Subsection "E#myid" An \f(CW\*(C`E\*(C'\fR element with \f(CW\*(C`ID\*(C'\fR equal to \*(L"myid\*(R". .PP .Vb 1 \& my $foo = $css\->select(\*(Aqdiv#foo\*(Aq); .Ve .SS "E:not(s)" .IX Subsection "E:not(s)" An \f(CW\*(C`E\*(C'\fR element that does not match simple selector \f(CW\*(C`s\*(C'\fR. .PP .Vb 1 \& my $others = $css\->select(\*(Aqdiv p:not(:first\-child)\*(Aq); .Ve .SS "E F" .IX Subsection "E F" An \f(CW\*(C`F\*(C'\fR element descendant of an \f(CW\*(C`E\*(C'\fR element. .PP .Vb 1 \& my $headlines = $css\->select(\*(Aqdiv h1\*(Aq); .Ve .SS "E > F" .IX Subsection "E > F" An \f(CW\*(C`F\*(C'\fR element child of an \f(CW\*(C`E\*(C'\fR element. .PP .Vb 1 \& my $headlines = $css\->select(\*(Aqhtml > body > div > h1\*(Aq); .Ve .SS "E + F" .IX Subsection "E + F" An \f(CW\*(C`F\*(C'\fR element immediately preceded by an \f(CW\*(C`E\*(C'\fR element. .PP .Vb 1 \& my $second = $css\->select(\*(Aqh1 + h2\*(Aq); .Ve .SS "E ~ F" .IX Subsection "E ~ F" An \f(CW\*(C`F\*(C'\fR element preceded by an \f(CW\*(C`E\*(C'\fR element. .PP .Vb 1 \& my $second = $css\->select(\*(Aqh1 ~ h2\*(Aq); .Ve .SS "E, F, G" .IX Subsection "E, F, G" Elements of type \f(CW\*(C`E\*(C'\fR, \f(CW\*(C`F\*(C'\fR and \f(CW\*(C`G\*(C'\fR. .PP .Vb 1 \& my $headlines = $css\->select(\*(Aqh1, h2, h3\*(Aq); .Ve .SS "E[foo=bar][bar=baz]" .IX Subsection "E[foo=bar][bar=baz]" An \f(CW\*(C`E\*(C'\fR element whose attributes match all following attribute selectors. .PP .Vb 1 \& my $links = $css\->select(\*(Aqa[foo^=b][foo$=ar]\*(Aq); .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::DOM::CSS implements the following attributes. .SS "tree" .IX Subsection "tree" .Vb 2 \& my $tree = $css\->tree; \& $css = $css\->tree([\*(Aqroot\*(Aq]); .Ve .PP Document Object Model. Note that this structure should only be used very carefully since it is very dynamic. .SH "METHODS" .IX Header "METHODS" Mojo::DOM::CSS inherits all methods from Mojo::Base and implements the following new ones. .SS "match" .IX Subsection "match" .Vb 1 \& my $bool = $css\->match(\*(Aqhead > title\*(Aq); .Ve .PP Match \s-1CSS\s0 selector against first node in \*(L"tree\*(R". .SS "select" .IX Subsection "select" .Vb 1 \& my $results = $css\->select(\*(Aqhead > title\*(Aq); .Ve .PP Run \s-1CSS\s0 selector against \*(L"tree\*(R". .SS "select_one" .IX Subsection "select_one" .Vb 1 \& my $result = $css\->select_one(\*(Aqhead > title\*(Aq); .Ve .PP Run \s-1CSS\s0 selector against \*(L"tree\*(R" and stop as soon as the first node matched. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .