| 1 | package Mojolicious::Plugin::MoreHTMLHelpers; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Some general helpers | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = 0.02; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 2 | my ($self, $app, $config) = @_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 17 | ▶ | $app->helper( textcolor => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 16 | 17 | my $c = shift; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 17 | ▶ | my $color = shift // '#000000'; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() // "#000000"
MC/DC100%1/1
shift() // "#000000"
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 17 | my ($red, $green, $blue); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 17 | ▶ | if ( length $color == 7 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 23 | 12 | ($red, $green, $blue) = $color =~ m{\#(..)(..)(..)}; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | elsif ( length $color == 4 ) { | ||||||||||||||||||||||||||||
| 26 | 3 | ($red, $green, $blue) = $color =~ m{\#(.)(.)(.)}; | |||||||||||||||||||||||||||
| 27 | 3 | for ( $red, $green, $blue ) { | |||||||||||||||||||||||||||
| 28 | 9 | $_ = $_ x 2; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 17 | my $brightness = _perceived_brightness( $red, $green, $blue ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 17 | ▶ | return $brightness > 130 ? '#000000' : '#ffffff'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 2 | } ); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 3 | ▶ | $app->helper( gradient => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 38 | 3 | my ($c) = shift; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 3 | ▶ | my $color = shift // '#ffffff'; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() // "#ffffff"
MC/DC100%1/1
shift() // "#ffffff"
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 3 | return sprintf q~ | |||||||||||||||||||||||||||
| 43 | background: %s !important; | ||||||||||||||||||||||||||||
| 44 | background: -moz-linear-gradient(top, %s 0%%,%s 100%%) !important; | ||||||||||||||||||||||||||||
| 45 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%%, %s), color-stop(100%%,%s)) !important; | ||||||||||||||||||||||||||||
| 46 | background: -webkit-linear-gradient(top, %s 0%%,%s 100%%) !important; | ||||||||||||||||||||||||||||
| 47 | background: -o-linear-gradient(top, %s 0%%,%s 100%%) !important; | ||||||||||||||||||||||||||||
| 48 | background: -ms-linear-gradient(top, %s 0%%,%s 100%%) !important; | ||||||||||||||||||||||||||||
| 49 | background: linear-gradient(to bottom,%s 0%%,%s 100%%) !important; | ||||||||||||||||||||||||||||
| 50 | ~, ($color) x 13; | ||||||||||||||||||||||||||||
| 51 | 2 | }); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 17 | ▶ | sub _perceived_brightness { | ||||||||||||||||||||||||||
|
Subroutine
_perceived_brightness: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 55 | 17 | my ($red, $green, $blue) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 17 | ▶ | if ( grep { !defined $_ || $_ =~ m{[^A-Fa-f0-9]} }($red, $green, $blue) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
!defined($_) || $_ =~ /[^A-Fa-f0-9]/u
MC/DC100%2/2
!defined($_) || $_ =~ /[^A-Fa-f0-9]/u
!defined($_)
$_ =~ /[^A-Fa-f0-9]/u
Truth table100%3/3
not(A) || B
A= !defined($_)B= $_ =~ /[^A-Fa-f0-9]/u
| |||||||||||||||||||||||||||||
| 58 | 4 | return 200; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 13 | $red = hex $red; | |||||||||||||||||||||||||||
| 62 | 13 | $green = hex $green; | |||||||||||||||||||||||||||
| 63 | 13 | $blue = hex $blue; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 13 | my $brightness = int ( sqrt ( | |||||||||||||||||||||||||||
| 66 | ( $red * $red * .299 ) + | ||||||||||||||||||||||||||||
| 67 | ( $green * $green * .587 ) + | ||||||||||||||||||||||||||||
| 68 | ( $blue * $blue * .114 ) | ||||||||||||||||||||||||||||
| 69 | )); | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 13 | return $brightness; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | 1; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||