File Coverage

blib/lib/Tags/HTML/GradientIndicator.pm
Criterion Covered Total %
statement 39 39 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 49 49 100.0


line stmt bran cond sub pod time code
1             package Tags::HTML::GradientIndicator;
2              
3 5     5   212712 use base qw(Tags::HTML);
  5         7  
  5         2608  
4 5     5   46039 use strict;
  5         9  
  5         111  
5 5     5   21 use warnings;
  5         12  
  5         2257  
6              
7 5     5   50 use Class::Utils qw(set_params split_params);
  5         10  
  5         275  
8 5     5   26 use Error::Pure qw(err);
  5         9  
  5         259  
9 5     5   2957 use Mo::utils::CSS 0.07 qw(check_css_unit);
  5         50827  
  5         121  
10              
11             our $VERSION = 0.06;
12              
13             # Constructor.
14             sub new {
15 14     14 1 1071249 my ($class, @params) = @_;
16              
17             # Create object.
18 14         79 my ($object_params_ar, $other_params_ar) = split_params(
19             ['css_background_image', 'css_gradient_class', 'height', 'width'], @params);
20 14         602 my $self = $class->SUPER::new(@{$other_params_ar});
  14         80  
21              
22             # Default gradient is left-right direction from red to violet.
23 12         493 $self->{'css_background_image'} = 'linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet)';
24              
25             # Gradient CSS class.
26 12         34 $self->{'css_gradient_class'} = 'gradient';
27              
28             # Height.
29 12         39 $self->{'height'} = '30px';
30              
31             # Width.
32 12         26 $self->{'width'} = '500px';
33              
34             # Process params.
35 12         22 set_params($self, @{$object_params_ar});
  12         56  
36              
37             # Check height;
38 12         141 check_css_unit($self, 'height');
39              
40             # Check width.
41 9         858 check_css_unit($self, 'width');
42              
43             # Object.
44 6         419 return $self;
45             }
46              
47             # Process 'Tags'.
48             sub _process {
49 3     3   2630 my ($self, $percent_value) = @_;
50              
51             # Value.
52 3         19 my ($width_value, $unit) = $self->{'width'} =~ m/^(\d+)(.*?)$/ms;
53 3         9 my $value = $percent_value * ($width_value / 100);
54              
55             # Main stars.
56             $self->{'tags'}->put(
57             ['b', 'div'],
58             ['a', 'style', 'width: '.$value.$unit.';overflow: hidden;'],
59              
60             ['b', 'div'],
61 3         28 ['a', 'class', $self->{'css_gradient_class'}],
62             ['e', 'div'],
63              
64             ['e', 'div'],
65             );
66              
67 3         434 return;
68             }
69              
70             # Process 'CSS::Struct'.
71             sub _process_css {
72 1     1   17 my $self = shift;
73              
74             $self->{'css'}->put(
75             ['s', '.'.$self->{'css_gradient_class'}],
76             ['d', 'height', $self->{'height'}],
77             ['d', 'width', $self->{'width'}],
78             ['d', 'background-color', 'red'],
79 1         16 ['d', 'background-image', $self->{'css_background_image'}],
80             ['e'],
81             );
82              
83 1         184 return;
84             }
85              
86             1;
87              
88             __END__