File Coverage

blib/lib/CSS/Object/Selector.pm
Criterion Covered Total %
statement 23 24 95.8
branch 1 2 50.0
condition 1 2 50.0
subroutine 7 8 87.5
pod 4 4 100.0
total 36 40 90.0


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## CSS Object Oriented - ~/lib/CSS/Object/Selector.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::Selector;
14             BEGIN
15             {
16 6     6   40 use strict;
  6         13  
  6         219  
17 6     6   66 use warnings;
  6         11  
  6         304  
18 6     6   29 use parent qw( CSS::Object::Element );
  6         11  
  6         43  
19 6     6   2268 our $VERSION = 'v0.2.0';
20             };
21              
22             sub init
23             {
24 48     48 1 7660 my $self = shift( @_ );
25 48         629 $self->{name} = '';
26 48         166 $self->{format} = '';
27 48         129 $self->{_init_strict_use_sub} = 1;
28 48         282 $self->SUPER::init( @_ );
29 48         153 return( $self );
30             }
31              
32             ## Inherited
33             ## sub format
34              
35             sub add_to
36             {
37 14     14 1 33 my $self = shift( @_ );
38 14   50     85 my $rule = shift( @_ ) || return( $self->error( "No rule object was provided to add our selctor to it." ) );
39 14 50       11819 return( $self->error( "Rule object provided (", overload::StrVal( $rule ), ") is not actually a CSS::Object::Rule object." ) ) if( !$self->_is_a( $rule, 'CSS::Object::Rule' ) );
40 14         644 $self->format->indent( $rule->format->indent );
41 14         24768 $rule->add_selector( $self );
42 14         83 return( $self );
43             }
44              
45 0     0 1 0 sub as_string { return( shift->name ); }
46              
47 463     463 1 14268 sub name { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); }
48              
49             1;
50             # NOTE: POD
51             __END__
52              
53             =encoding utf-8
54              
55             =head1 NAME
56              
57             CSS::Object::Selector - CSS Object Oriented Selector
58              
59             =head1 SYNOPSIS
60              
61             use CSS::Object::Selector;
62             my $sel = CSS::Object::Selector->new(
63             name => $css_selector,
64             debug => 3,
65             format => $format_object
66             ) || die( CSS::Object::Selector->error );
67              
68             =head1 VERSION
69              
70             v0.2.0
71              
72             =head1 DESCRIPTION
73              
74             L<CSS::Object::Selector> is a class to contain the name of a selector. For any given css rule, there can be multiple selectors.
75              
76             Selector objects can be accessed with L<CSS::Object::Rule/selectors> which is an L<Module::Generic::Array> object.
77              
78             =head1 CONSTRUCTOR
79              
80             =head2 new
81              
82             To instantiate a new L<CSS::Object::Selector> object, pass an hash reference of following parameters:
83              
84             =over 4
85              
86             =item I<debug>
87              
88             This is an integer. The bigger it is and the more verbose is the output.
89              
90             =item I<format>
91              
92             This is a L<CSS::Object::Format> object or one of its child modules.
93              
94             =item I<name>
95              
96             This is the selector's name. When provided, this calls the method L</name> to store the value.
97              
98             =back
99              
100             =head1 METHODS
101              
102             =head2 add_to
103              
104             Provided with a L<CSS::Object::Rule> object, and this will add our selector object to it by calling L<CSS::Object::Rule/add_selector>
105              
106             It returns our selector object to allow chaining.
107              
108             =head2 as_string
109              
110             This returns the selector's name.
111              
112             Maybe, this should be changed to calling a method B<selector_as_string> in the L<CSS::Object::Format>, but the reasons for modifying a selector's name are limited.
113              
114             =head2 format
115              
116             This is a L<CSS::Object::Format> object or one of its child modules.
117              
118             =head2 name
119              
120             Sets or gets the selector's name. The name stored here becomes a L<Module::Generic::Scalar> and thus all its object methods can be used
121              
122             =head1 AUTHOR
123              
124             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
125              
126             =head1 SEE ALSO
127              
128             L<CSS::Object>
129              
130             =head1 COPYRIGHT & LICENSE
131              
132             Copyright (c) 2020 DEGUEST Pte. Ltd.
133              
134             You can use, copy, modify and redistribute this package and associated
135             files under the same terms as Perl itself.
136              
137             =cut