line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::MoreHTMLHelpers; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Some general helpers |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
505
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
373
|
use parent 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
233
|
|
|
1
|
|
|
|
|
4
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.01; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub register { |
13
|
1
|
|
|
1
|
1
|
435
|
my ($self, $app, $config) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$app->helper( textcolor => sub { |
16
|
12
|
|
|
12
|
|
66019
|
my $c = shift; |
17
|
|
|
|
|
|
|
|
18
|
12
|
|
50
|
|
|
33
|
my $color = shift // '#000000'; |
19
|
|
|
|
|
|
|
|
20
|
12
|
|
|
|
|
11
|
my ($red, $green, $blue); |
21
|
|
|
|
|
|
|
|
22
|
12
|
100
|
|
|
|
36
|
if ( length $color == 7 ) { |
|
|
50
|
|
|
|
|
|
23
|
9
|
|
|
|
|
39
|
($red, $green, $blue) = $color =~ m{\#(..)(..)(..)}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
elsif ( length $color == 4 ) { |
26
|
3
|
|
|
|
|
16
|
($red, $green, $blue) = $color =~ m{\#(.)(.)(.)}; |
27
|
3
|
|
|
|
|
7
|
for ( $red, $green, $blue ) { |
28
|
9
|
|
|
|
|
15
|
$_ = $_ x 2; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
12
|
|
|
|
|
33
|
my $brightness = _perceived_brightness( $red, $green, $blue ); |
33
|
|
|
|
|
|
|
|
34
|
12
|
100
|
|
|
|
40
|
return $brightness > 130 ? '#000000' : '#ffffff'; |
35
|
1
|
|
|
|
|
6
|
} ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _perceived_brightness { |
39
|
12
|
|
|
12
|
|
14
|
my ($red, $green, $blue) = @_; |
40
|
|
|
|
|
|
|
|
41
|
12
|
|
|
|
|
26
|
$red = hex $red; |
42
|
12
|
|
|
|
|
14
|
$green = hex $green; |
43
|
12
|
|
|
|
|
13
|
$blue = hex $blue; |
44
|
|
|
|
|
|
|
|
45
|
12
|
|
|
|
|
38
|
my $brightness = int ( sqrt ( |
46
|
|
|
|
|
|
|
( $red * $red * .299 ) + |
47
|
|
|
|
|
|
|
( $green * $green * .587 ) + |
48
|
|
|
|
|
|
|
( $blue * $blue * .114 ) |
49
|
|
|
|
|
|
|
)); |
50
|
|
|
|
|
|
|
|
51
|
12
|
|
|
|
|
14
|
return $brightness; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |