blib/lib/Term/Fabulous/ThemeEditor/UI.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 85 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Term::Fabulous::ThemeEditor::UI;
2  
3 use v5.32;
4 use warnings;
5 use feature 'signatures';
6 no warnings 'experimental::signatures';
7  
8 our $VERSION = '0.05';
9  
10 use Object::Pad 0.825;
11  
12 use Term::Fabulous;
13  
14 # The Term::Fabulous of the theme editor: the editor itself draws with the
15 # UI's theme, the preview of the theme being edited with that theme.
16 class Term::Fabulous::ThemeEditor::UI :isa(Term::Fabulous) :strict(params) {
17 use Scalar::Util qw(blessed refaddr weaken);
18  
19 # The widgets whose subtrees show the preview: the preview pane, and the
20 # dialogs and toasts opened from it (weakened: they go when closed).
21 field %preview_roots;
22 field $preview_theme;
23  
24 method add_preview_root ($widget) {
25 delete @preview_roots{ grep { !defined $preview_roots{$_} } keys %preview_roots }; # roots that are gone
26 weaken( $preview_roots{ refaddr $widget } = $widget );
27 $self->refresh_looks;
28 return $self;
29 }
30  
31 method preview_theme (@new) {
32 return $preview_theme unless @new;
33 die "Term::Fabulous::ThemeEditor::UI: the preview theme must be a Term::Fabulous::Theme" unless blessed $new[0] && $new[0]->isa('Term::Fabulous::Theme');
34 return $preview_theme if defined $preview_theme && refaddr $preview_theme == refaddr $new[0];
35 $preview_theme = $new[0];
36 $self->refresh_looks;
37 return $preview_theme;
38 }
39  
40 method is_in_preview ($widget) {
41 foreach my $node ( $widget, $widget->ancestors ) {
42 return 1 if defined $preview_roots{ refaddr $node };
43 my $dialog = $node->can('dialog') ? $node->dialog : undef; # a dialog's backdrop draws as its dialog
44 return 1 if defined $dialog && defined $preview_roots{ refaddr $dialog };
45 }
46 return 0;
47 }
48  
49 method theme_for :override ($widget) {
50 return $self->SUPER::theme_for($widget) unless defined $preview_theme && $self->is_in_preview($widget);
51 return $preview_theme;
52 }
53 }
54  
55 1;
56  
57 __END__