/usr/share/perl5/CSS.pm is in libcss-perl 1.08-1+nmu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | package CSS;
$VERSION = 1.08;
use strict;
use warnings;
use Carp;
use CSS::Style;
use CSS::Selector;
use CSS::Property;
use CSS::Adaptor;
use Data::Dumper;
sub new {
my $class = shift;
my $self = bless {}, $class;
my $options = shift;
$self->{styles} = [];
$self->{parser} = $options->{parser} || 'CSS::Parse::Lite';
$self->{adaptor} = $options->{adaptor} || 'CSS::Adaptor';
return $self;
}
sub read_file {
my $self = shift;
my $path = shift;
if (ref $path){
if (ref $path eq 'ARRAY'){
$self->read_file($_) for @$path;
return 1;
}
} else {
if ($path){
local *IN;
open(IN, $path) or croak "couldn't open file: $!";
my $source = join '',<IN>;
close(IN);
$self->parse_string($source) if $source;
return 1;
}
}
croak "only scalars and arrays accepted: $!";
}
sub read_string {
my $self = shift;
my $data = shift;
if (ref $data){
if (ref $data eq 'ARRAY'){
$self->read_string($_) for @$data;
return 1;
}
} else {
$self->parse_string($data) if length $data;
}
}
sub parse_string {
my $self = shift;
my $string = shift;
# remove comments
$string =~ s!/\*.*?\*\/!!g;
$string =~ s|<!--||g;
$string =~ s|-->||g;
eval "use $self->{parser}";
my $parser_obj = new $self->{parser};
$parser_obj->{'parent'} = $self;
$parser_obj->parse_string($string);
}
sub purge {
my $self = shift;
$self->{styles} = [];
}
sub set_adaptor {
my $self = shift;
my $adaptor = shift;
$self->{adaptor} = $adaptor;
for(@{$self->{styles}}){
$_->set_adaptor($adaptor);
}
}
sub output {
my $self = shift;
my $adaptor = shift || $self->{adaptor};
for(@{$self->{styles}}){
$_->set_adaptor($adaptor);
}
my $output = '';
for(@{$self->{styles}}){
$output .= "$_";
}
return $output;
}
sub get_style_by_selector {
my ($self, $sel_name) = @_;
for my $style (@{$self->{styles}}){
for my $selector (@{$style->{selectors}}){
if ($selector->{name} eq $sel_name){
return $style;
}
}
}
return 0;
}
1;
__END__
=head1 NAME
CSS - Object oriented access to Cascading Style Sheets (CSS)
=head1 SYNOPSIS
use CSS;
# create a CSS object with the default options
my $css = CSS->new();
# create a CSS object with a specific parser
my $css = CSS->new( { 'parser' => 'CSS::Parse::Lite' } );
my $css = CSS->new( { 'parser' => 'CSS::Parse::Heavy' } );
my $css = CSS->new( { 'parser' => 'CSS::Parse::Compiled' } );
# create a CSS object with a specific adaptor
my $css = CSS->new( { 'adaptor' => 'CSS::Adaptor' } );
my $css = CSS->new( { 'adaptor' => 'CSS::Adaptor::Pretty' } );
my $css = CSS->new( { 'adaptor' => 'CSS::Adaptor::Debug' } );
# parse some CSS from a string
$css->read_string( $css_data );
$css->read_string( ( $css_data, $more_css_data ) );
# parse some CSS from a file
$css->read_file( 'my_file.css' );
$css->read_file( ( 'my_file.css', 'my_other_file.css' ) );
# output the CSS using the current adaptor
print $css->output();
# set a new adaptor and then output the CSS
$css->set_adaptor( 'CSS::Adaptor::Foo' );
print $css->output();
# output the CSS using a tempory adaptor
print $css->output( 'CSS::Adaptor::Bar' );
# forget about the CSS we've already parsed
$css->purge();
=head1 DESCRIPTION
This module can be used, along with a CSS::Parse::* module, to parse
CSS data and represent it as a tree of objects. Using a CSS::Adaptor::*
module, the CSS data tree can then be transformed into other formats.
=head1 NOTICE
From version 1.00 of this module onwards, backwards compatibility is
broken. This is due to large changes in the way data is parsed and
then represented internally. Version 0.08 is still available on
CPAN: L<http://search.cpan.org/author/IAMCAL/CSS-0.08/>
=head1 TREE STRUCTURE
The CSS object is the head of the tree. It contains a list of
CSS::Style objects which each represent a CSS ruleset. Each of
these objects contains a list of selectors and properties. Each
selector is stored as a CSS::Selector object. Each property
object is stored as a CSS::Property object and contains a list
of values. These values are stored as CSS::Value objects.
foo, bar {
baz: fop;
woo: yay houpla;
}
The above example would be represented as a single CSS::Style object.
That object would then have two CSS::Selector objects representing
'foo' and 'bar'. It would also have two CSS::Property objects
representing 'baz' and 'woo'. The 'baz' object then has a single child
CSS::Value object for 'fop', whilst the 'woo' object has two
child objects for 'yay' and 'houpla'.
=head1 METHODS
=head2 CONSTRUCTOR
=over 4
=item C<new()> or C<new( { ..options.. } )>
An optional hash can contain arguments:
parser module to use as the CSS parser
adaptor adaptor to use for output
=back
=head2 ACCESSORS
=over 4
=item C<read_file( $filename )> or C<read_file( @filenames )>
Read one or mores files and parse the CSS within them.
=item C<read_string( $scalar )> or C<read_string( @strings )>
Read one or more strings and parse the CSS within them.
=item C<output()> or C<output( 'CSS::Adaptor::Foo' )>
Return a string representation of the CSS tree, using either the
current adaptor or the specified one.
=item C<set_adaptor( 'CSS::Adaptor::Bar' )>
Set the current adaptor for the CSS tree.
=item C<purge()>
Forget all the objects in the CSS tree;
=item C<get_style_by_selector( 'selector_name' )>
Returns the first CSS::Style object with the specified selector
name attached. Returns zero on failure.
=back
=head1 AUTHORS
Copyright (C) 2001-2002, Allen Day <allenday@ucla.edu>
Copyright (C) 2003-2004, Cal Henderson <cal@iamcal.com>
=head1 SEE ALSO
L<CSS::Style>, L<CSS::Selector>, L<CSS::Property>, L<CSS::Value>,
L<CSS::Parse>, L<CSS::Parse::Lite>, L<CSS::Parse::Heavy>,
L<CSS::Parse::Compiled>, L<CSS::Parse::PRDGrammar>, L<CSS::Adaptor>,
L<CSS::Adaptor::Pretty>, L<CSS::Adaptor::Debug>, perl(1)
=cut
|