line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Color::Theme::Role; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2014-12-11'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.01'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
633
|
use 5.010001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
35
|
|
7
|
1
|
|
|
1
|
|
5
|
use Moo::Role; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has color_theme_args => (is => 'rw', default => sub { {} }); |
10
|
|
|
|
|
|
|
has _all_color_themes => (is => 'rw'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub color_theme_module_prefix { |
13
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
14
|
|
|
|
|
|
|
|
15
|
0
|
0
|
|
|
|
|
(ref($self) ? ref($self) : $self ) . '::ColorTheme'; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub color_theme { |
19
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
if (!@_) { return $self->{color_theme} } |
|
0
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $ct = shift; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $p2 = ""; |
25
|
0
|
0
|
|
|
|
|
if (!ref($ct)) { |
26
|
0
|
|
|
|
|
|
$p2 = " named $ct"; |
27
|
0
|
|
|
|
|
|
$ct = $self->get_color_theme($ct); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $err; |
31
|
0
|
0
|
0
|
|
|
|
if (!$ct->{no_color} && !$self->use_color) { |
32
|
0
|
|
|
|
|
|
$err = "color theme uses color but use_color is set to false"; |
33
|
|
|
|
|
|
|
} |
34
|
0
|
0
|
|
|
|
|
die "Can't select color theme$p2: $err" if $err; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
$self->{color_theme} = $ct; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub get_color_theme { |
40
|
0
|
|
|
0
|
1
|
|
my ($self, $ct) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $prefix = $self->color_theme_module_prefix; |
43
|
0
|
|
|
|
|
|
my $cts; |
44
|
|
|
|
|
|
|
my $pkg; |
45
|
0
|
0
|
|
|
|
|
if ($ct =~ s/(.+):://) { |
46
|
0
|
|
|
|
|
|
$pkg = "$prefix\::$1"; |
47
|
0
|
|
|
|
|
|
my $pkgp = $pkg; $pkgp =~ s!::!/!g; |
|
0
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
require "$pkgp.pm"; |
49
|
1
|
|
|
1
|
|
559
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
291
|
|
50
|
0
|
|
|
|
|
|
$cts = \%{"$pkg\::color_themes"}; |
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} else { |
52
|
|
|
|
|
|
|
#$cts = $self->list_color_themes(1); |
53
|
0
|
|
|
|
|
|
die "Please use SubPackage::name to choose color theme, ". |
54
|
|
|
|
|
|
|
"use list_color_themes() to list available themes"; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
0
|
|
|
|
|
$cts->{$ct} or die "Unknown color theme name '$ct'". |
|
|
0
|
|
|
|
|
|
57
|
|
|
|
|
|
|
($pkg ? " in package $pkg" : ""); |
58
|
0
|
0
|
0
|
|
|
|
($cts->{$ct}{v} // 1.0) == 1.1 or die "Color theme '$ct' is too old ". |
|
|
0
|
|
|
|
|
|
59
|
|
|
|
|
|
|
"(v < 1.1)". ($pkg ? ", please upgrade $pkg" : ""); |
60
|
0
|
|
|
|
|
|
$cts->{$ct}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub get_theme_color { |
64
|
0
|
|
|
0
|
1
|
|
my ($self, $item_name) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
return undef if $self->{color_theme}{no_color}; |
67
|
0
|
|
|
|
|
|
$self->{color_theme}{colors}{$item_name}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub get_theme_color_as_rgb { |
71
|
0
|
|
|
0
|
1
|
|
my ($self, $item_name, $args) = @_; |
72
|
0
|
|
|
|
|
|
my $c = $self->get_theme_color($item_name); |
73
|
0
|
0
|
|
|
|
|
return undef unless defined($c); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# resolve coderef color |
76
|
0
|
0
|
|
|
|
|
if (ref($c) eq 'CODE') { |
77
|
0
|
|
0
|
|
|
|
$args //= {}; |
78
|
0
|
|
|
|
|
|
$c = $c->($self, %$args); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$c; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub list_color_themes { |
85
|
0
|
|
|
0
|
1
|
|
require Module::List; |
86
|
0
|
|
|
|
|
|
require Module::Load; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my ($self, $detail) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $prefix = $self->color_theme_module_prefix; |
91
|
0
|
|
|
|
|
|
my $all_ct = $self->_all_color_themes; |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
if (!$all_ct) { |
94
|
0
|
|
|
|
|
|
my $mods = Module::List::list_modules("$prefix\::", |
95
|
|
|
|
|
|
|
{list_modules=>1, recurse=>1}); |
96
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
202
|
|
97
|
0
|
|
|
|
|
|
$all_ct = {}; |
98
|
0
|
|
|
|
|
|
for my $mod (sort keys %$mods) { |
99
|
|
|
|
|
|
|
#$log->tracef("Loading color theme module '%s' ...", $mod); |
100
|
0
|
|
|
|
|
|
Module::Load::load($mod); |
101
|
0
|
|
|
|
|
|
my $ct = \%{"$mod\::color_themes"}; |
|
0
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
for (keys %$ct) { |
103
|
0
|
|
|
|
|
|
my $cutmod = $mod; |
104
|
0
|
|
|
|
|
|
$cutmod =~ s/^\Q$prefix\E:://; |
105
|
0
|
|
|
|
|
|
my $name = "$cutmod\::$_"; |
106
|
0
|
|
|
|
|
|
$ct->{$_}{name} = $name; |
107
|
0
|
|
|
|
|
|
$all_ct->{$name} = $ct->{$_}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
0
|
|
|
|
|
|
$self->_all_color_themes($all_ct); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
if ($detail) { |
114
|
0
|
|
|
|
|
|
return $all_ct; |
115
|
|
|
|
|
|
|
} else { |
116
|
0
|
|
|
|
|
|
return sort keys %$all_ct; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
# ABSTRACT: Role for class wanting to support color themes |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |