File Coverage

blib/lib/CSS/Object/Parser.pm
Criterion Covered Total %
statement 18 19 94.7
branch 2 4 50.0
condition 1 2 50.0
subroutine 6 7 85.7
pod 3 3 100.0
total 30 35 85.7


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## CSS Object Oriented - ~/lib/CSS/Object/Parser.pm
3             ## Version v0.2.0
4             ## Copyright(c) 2020 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2020/06/21
7             ## Modified 2024/09/05
8             ## All rights reserved
9             ##
10             ## This program is free software; you can redistribute it and/or modify it
11             ## under the same terms as Perl itself.
12             ##----------------------------------------------------------------------------
13             package CSS::Object::Parser;
14             BEGIN
15             {
16 4     4   3241 use strict;
  4         10  
  4         175  
17 4     4   23 use warnings;
  4         8  
  4         250  
18 4     4   23 use parent qw( Module::Generic );
  4         8  
  4         29  
19 4     4   1289 our $VERSION = 'v0.2.0';
20             };
21              
22             sub init
23             {
24 6     6 1 1319 my $self = shift( @_ );
25 6   50     29 my $css = shift( @_ ) ||
26             return( $self->error( "No CSS object provided." ) );
27 6 50       36 return( $self->error( "CSS object provded is actually not a CSS::Object object." ) ) if( !$self->_is_a( $css, 'CSS::Object' ) );
28 6         536 $self->{_init_strict_use_sub} = 1;
29 6         67 $self->SUPER::init( @_ );
30 6 50       515 $self->css( $css ) || return( $self->pass_error );
31 6         1771 return( $self );
32             }
33              
34 24     24 1 158 sub css { return( shift->_set_get_object( 'css', 'CSS::Object', @_ ) ); }
35              
36 0     0 1   sub parse_string { return( shift->error( "You cannot use this class directly. Please use one of the Parser subclasses." ) ); }
37              
38             1;
39             # NOTE: POD
40             __END__
41              
42             =encoding utf-8
43              
44             =head1 NAME
45              
46             CSS::Object::Parser - CSS Object Oriented Parser
47              
48             =head1 SYNOPSIS
49              
50             use CSS::Object::Parser;
51             my $parser = CSS::Object::Parser->new( debug => 3 );
52             my $rules = $parser->parse_string( $css_text_data ) ||
53             die( CSS::Object::Parser->error );
54             printf( "Found %d rules\n", $rules->length );
55              
56             =head1 VERSION
57              
58             v0.2.0
59              
60             =head1 DESCRIPTION
61              
62             L<CSS::Object::Parser> is base CSS parser for L<CSS::Object>
63              
64             =head1 CONSTRUCTOR
65              
66             =head2 new
67              
68             To instantiate a new L<CSS::Object::Parser> object, pass an hash reference of following parameters:
69              
70             =over 4
71              
72             =item I<debug>
73              
74             This is an integer. The bigger it is and the more verbose is the output.
75              
76             =item I<format>
77              
78             This is a L<CSS::Object::Format> object or one of its child modules.
79              
80             =back
81              
82             =head1 METHODS
83              
84             =head2 css
85              
86             This sets or gets a L<CSS::Object> object. This object is used to create css elements and store them with the L<CSS::Object/add_element> method.
87              
88             =head2 format
89              
90             This is a L<CSS::Object::Format> object or one of its child modules.
91              
92             =head2 parse_string
93              
94             In this base module, this method does nothing but trigger an error that it should not be called directly, but instead use this module sub classes.
95              
96             =head1 AUTHOR
97              
98             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
99              
100             =head1 SEE ALSO
101              
102             L<CSS::Object>
103              
104             =head1 COPYRIGHT & LICENSE
105              
106             Copyright (c) 2020 DEGUEST Pte. Ltd.
107              
108             You can use, copy, modify and redistribute this package and associated
109             files under the same terms as Perl itself.
110              
111             =cut