| 1 | package Tags::HTML::Stars; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Class::Utils qw(set_params); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use List::Util qw(max); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # Constants. | ||||||||||||||||||||||||||||
| 13 | 4 | Readonly::Scalar our $STAR_FULL_FILENAME => 'Star*.svg'; | |||||||||||||||||||||||||||
| 14 | 4 | Readonly::Scalar our $STAR_HALF_FILENAME => 'Star-.svg'; | |||||||||||||||||||||||||||
| 15 | 4 | Readonly::Scalar our $STAR_NOTHING_FILENAME => 'Star½.svg'; | |||||||||||||||||||||||||||
| 16 | 4 | Readonly::Scalar our $IMG_STAR_FULL => encode_base64(<<'END', ''); | |||||||||||||||||||||||||||
| 17 | <svg width="300px" height="275px" viewBox="0 0 300 275" xmlns="http://www.w3.org/2000/svg" version="1.1"> | ||||||||||||||||||||||||||||
| 18 | <polygon fill="#fdff00" stroke="#605a00" stroke-width="15" points="150,25 179,111 269,111 197,165 223,251 150,200 77,251 103,165 31,111 121,111" /> | ||||||||||||||||||||||||||||
| 19 | </svg> | ||||||||||||||||||||||||||||
| 20 | END | ||||||||||||||||||||||||||||
| 21 | 4 | Readonly::Scalar our $IMG_STAR_HALF => encode_base64(<<'END', ''); | |||||||||||||||||||||||||||
| 22 | <svg width="300px" height="275px" viewBox="0 0 300 275" xmlns="http://www.w3.org/2000/svg" version="1.1"> | ||||||||||||||||||||||||||||
| 23 | <clipPath id="empty"><rect x="150" y="0" width="150" height="275" /></clipPath> | ||||||||||||||||||||||||||||
| 24 | <clipPath id="filled"><rect x="0" y="0" width="150" height="275" /></clipPath> | ||||||||||||||||||||||||||||
| 25 | <polygon fill="none" stroke="#808080" stroke-width="15" stroke-opacity="0.37647060" points="150,25 179,111 269,111 197,165 223,251 150,200 77,251 103,165 31,111 121,111" clip-path="url(#empty)" /> | ||||||||||||||||||||||||||||
| 26 | <polygon fill="#fdff00" stroke="#605a00" stroke-width="15" points="150,25 179,111 269,111 197,165 223,251 150,200 77,251 103,165 31,111 121,111" clip-path="url(#filled)" /> | ||||||||||||||||||||||||||||
| 27 | </svg> | ||||||||||||||||||||||||||||
| 28 | END | ||||||||||||||||||||||||||||
| 29 | 4 | Readonly::Scalar our $IMG_STAR_NOTHING => encode_base64(<<'END', ''); | |||||||||||||||||||||||||||
| 30 | <svg width="300px" height="275px" viewBox="0 0 300 275" xmlns="http://www.w3.org/2000/svg" version="1.1"> | ||||||||||||||||||||||||||||
| 31 | <polygon fill="none" stroke="#808080" stroke-width="15" stroke-opacity="0.37647060" points="150,25 179,111 269,111 197,165 223,251 150,200 77,251 103,165 31,111 121,111" /> | ||||||||||||||||||||||||||||
| 32 | </svg> | ||||||||||||||||||||||||||||
| 33 | END | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 4 | our $VERSION = 0.01; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # Constructor. | ||||||||||||||||||||||||||||
| 38 | sub new { | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | my ($class, @params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # Create object. | ||||||||||||||||||||||||||||
| 42 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # Public image directory. | ||||||||||||||||||||||||||||
| 45 | 0 | $self->{'public_image_dir'} = undef; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Star width (300px). | ||||||||||||||||||||||||||||
| 48 | 0 | $self->{'star_width'} = undef; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # 'Tags::Output' object. | ||||||||||||||||||||||||||||
| 51 | 0 | $self->{'tags'} = undef; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # Process params. | ||||||||||||||||||||||||||||
| 54 | 0 | set_params($self, @params); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # Check to 'Tags' object. | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if (! $self->{'tags'} || ! $self->{'tags'}->isa('Tags::Output')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"tags"} and $self->{"tags"}->isa("Tags::Output")
MC/DC0%0/2
$self->{"tags"} and $self->{"tags"}->isa("Tags::Output")
$self->{"tags"}
$self->{"tags"}->isa("Tags::Output")
Truth table0%0/3
A and B
A= $self->{"tags"}B= $self->{"tags"}->isa("Tags::Output")
| |||||||||||||||||||||||||||||
| 58 | 0 | err "Parameter 'tags' must be a 'Tags::Output::*' class."; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # Object. | ||||||||||||||||||||||||||||
| 62 | 0 | return $self; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # Process 'Tags'. | ||||||||||||||||||||||||||||
| 66 | sub process { | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my ($self, $stars_hr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
process: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # Main stars. | ||||||||||||||||||||||||||||
| 70 | 0 | $self->{'tags'}->put( | |||||||||||||||||||||||||||
| 71 | ['b', 'div'], | ||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | my $max_num = max(keys %{$stars_hr}); | |||||||||||||||||||||||||||
| 75 | 0 | foreach my $num (1 .. $max_num) { | |||||||||||||||||||||||||||
| 76 | 0 | my $image_src = $self->_star_src($stars_hr->{$num}); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | $self->{'tags'}->put( | ||||||||||||||||||||||||||||
| 79 | ['b', 'img'], | ||||||||||||||||||||||||||||
| 80 | ( | ||||||||||||||||||||||||||||
| 81 | $self->{'star_width'} | ||||||||||||||||||||||||||||
| 82 | ? ( | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | ['a', 'style', 'width: '.$self->{'star_width'}.';'], | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | ) : (), | ||||||||||||||||||||||||||||
| 85 | ), | ||||||||||||||||||||||||||||
| 86 | ['a', 'src', $image_src], | ||||||||||||||||||||||||||||
| 87 | ['e', 'img'], | ||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | $self->{'tags'}->put( | |||||||||||||||||||||||||||
| 92 | ['e', 'div'], | ||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | return; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | sub _star_src { | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_star_src: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | # Link to file. | ||||||||||||||||||||||||||||
| 102 | 0 | my $src; | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | if (defined $self->{'public_image_dir'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | $src = $self->{'public_image_dir'}; | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($src ne '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | $src .= '/'; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($id eq 'full') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 109 | 0 | $src .= $STAR_FULL_FILENAME; | |||||||||||||||||||||||||||
| 110 | } elsif ($id eq 'half') { | ||||||||||||||||||||||||||||
| 111 | 0 | $src .= $STAR_HALF_FILENAME; | |||||||||||||||||||||||||||
| 112 | } elsif ($id eq 'nothing') { | ||||||||||||||||||||||||||||
| 113 | 0 | $src .= $STAR_NOTHING_FILENAME | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } else { | ||||||||||||||||||||||||||||
| 116 | 0 | $src = 'data:image/svg+xml;base64,'; | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ($id eq 'full') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 118 | 0 | $src .= $IMG_STAR_FULL; | |||||||||||||||||||||||||||
| 119 | } elsif ($id eq 'half') { | ||||||||||||||||||||||||||||
| 120 | 0 | $src .= $IMG_STAR_HALF; | |||||||||||||||||||||||||||
| 121 | } elsif ($id eq 'nothing') { | ||||||||||||||||||||||||||||
| 122 | 0 | $src .= $IMG_STAR_NOTHING; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | return $src; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 4 | 1; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||||||