CSS-SAC

 view release on metacpan or  search on metacpan

SAC.pm  view on Meta::CPAN

            $value = $1;
            $text = 'ident';
            $type = IDENT;
        }

        # string
        elsif ($$css =~ s/^($RE_STRING)//) {
            $value = $1;
            $value =~ s/^(?:"|')//; #"
            $value =~ s/(?:"|')$//; #"
            $text = 'string';
            $type = STRING_VALUE;
        }

        # error
        else {
            return [];
        }

        # add a lu
        push @lus, CSS::SAC::LexicalUnit->new($type,$text,$value);
    }

    return \@lus;
}
#---------------------------------------------------------------------#
*CSS::SAC::parsePropertyValue = \&parse_property_value;


#---------------------------------------------------------------------#
# $sac->parse_priority($string_ref)
# parses a priority
# returns true if there is a priority value there
#---------------------------------------------------------------------#
sub parse_priority {
    my $sac = shift;
    my $css = shift;

    return 1 if $$css =~ s/^\s*!\s*important//i;
}
#---------------------------------------------------------------------#
*CSS::SAC::parsePriority = \&parse_priority;


#                                                                     #
#                                                                     #
### Parsing Methods ###################################################



### Default Error Handler #############################################
#                                                                     #
#                                                                     #

# This is pretty much a non package, it is just there to provide the
# default error handler.

package CSS::SAC::DefaultErrorHandler;

sub new         { return bless [], __PACKAGE__; }
sub warning     { warn "[warning] $_[1] (line " . (caller)[2] . ")";       }
sub error       { warn "[error] $_[1] (line " . (caller)[2] . ")";         }
sub fatal_error { die  "[fatal] $_[1] (line " . (caller)[2] . ")";         }


#                                                                     #
#                                                                     #
### Default Error Handler #############################################



1;

=pod

=head1 NAME

CSS::SAC - SAC CSS parser

=head1 SYNOPSIS

  use CSS::SAC qw();
  use My::SACHandler ();
  use My::SACErrors ();

  my $doc_handler = My::SACHandler->new;
  my $err_handler = My::SACErrors->new;
  my $sac = CSS::SAC->new({
                           DocumentHandler => $doc_handler,
                           ErrorHandler    => $err_handler,
                         });

  # generate a stream of events
  $sac->parse({ filename => 'foo.css' });

=head1 DESCRIPTION

SAC (Simple API for CSS) is an event-based API much like SAX for XML.
If you are familiar with the latter, you should have little trouble
getting used to SAC. More information on SAC can be found online at
http://www.w3.org/TR/SAC.

CSS having more constructs than XML, core SAC is still more complex
than core SAX. However, if you need to parse a CSS style sheet, SAC
probably remains the easiest way to get it done.

Most of the spec is presently implemented. The following interfaces
are not yet there: Locator, CSSException, CSSParseException,
ParserFactory. They may or may not be implemented at a later date
(the most likely candidates are the exception classes, for which I
still have to find an appropriate model).

Some places differ slightly from what is in the spec. I have tried to
keep those to a justified minimum and to flag them correctly.

=head2 the CSS::SAC module itself

The Parser class doesn't exist separately, it's defined in CSS::SAC.
It doesn't expose the locale interface because we don't localize
errors (yet). It also doesn't have C<parse_style_sheet> but rather
C<parse>, which is more consistent with other Perl parsing interfaces.

I have added the C<charset($charset)> callback to the DocumentHandler



( run in 1.844 second using v1.01-cache-2.11-cpan-e93a5daba3e )