File Coverage

lib/App/Asciio/stripes/stripes.pm
Criterion Covered Total %
statement 20 59 33.9
branch n/a
condition n/a
subroutine 7 31 22.5
pod 0 27 0.0
total 27 117 23.0


line stmt bran cond sub pod time code
1              
2             package App::Asciio::stripes::stripes ;
3              
4 3     3   30 use strict;
  3         7  
  3         132  
5 3     3   18 use warnings;
  3         6  
  3         202  
6              
7 3     3   20 use List::Util qw(max) ;
  3         6  
  3         295  
8 3     3   21 use App::Asciio::String ;
  3         5  
  3         3930  
9              
10             #---------------------------------------------------------------------------
11              
12             sub new
13             {
14 0     0 0 0 my ($class, $element_definition) = @_ ;
15              
16 0         0 my @stripes ;
17              
18 0         0 my ($total_width, $total_height) = (0, 0) ;
19 0         0 my ($min_x, $min_y, $max_x, $max_y) = (0, 0, 0, 0) ;
20              
21 0         0 for my $stripe (@{$element_definition->{STRIPES}})
  0         0  
22             {
23 0         0 my $text = $stripe->{TEXT} ;
24            
25 0         0 my $width = max( map{ unicode_length($_) } split("\n", $text)) ;
  0         0  
26            
27 0         0 my $height = ($text =~ tr[\n][\n]) + 1 ;
28            
29             push @stripes,
30             {
31             TEXT => $text,
32             X_OFFSET => $stripe->{X_OFFSET},
33             Y_OFFSET => $stripe->{Y_OFFSET},
34 0         0 WIDTH => $width,
35             HEIGHT => $height ,
36             } ;
37            
38 0         0 ($total_width) = max($total_width, $stripe->{X_OFFSET} + $width) ;
39 0         0 ($total_height) = max($total_height, $stripe->{Y_OFFSET} + $height) ;
40            
41 0         0 ($min_x, $max_x) = minmax($min_x, $max_x, $stripe->{X_OFFSET}, $stripe->{X_OFFSET} + $width) ;
42 0         0 ($min_y, $max_y) = minmax($min_y, $max_y, $stripe->{Y_OFFSET}, $stripe->{Y_OFFSET} + $height) ;
43             }
44              
45 0         0 return bless
46             {
47             STRIPES => \@stripes,
48             EXTENTS => [$min_x, $max_x, $min_y, $max_y],
49             WIDTH => $total_width,
50             HEIGHT => $total_height,
51             }, __PACKAGE__ ;
52             }
53              
54             #---------------------------------------------------------------------------
55              
56 265     265 0 484 sub get_stripes { my ($self) = @_ ; return $self->{STRIPES} ; }
  265         830  
57              
58             #-----------------------------------------------------------------------------
59              
60 0     0 0 0 sub get_size { my ($self) = @_ ; return($self->{WIDTH}, $self->{HEIGHT}) ; }
  0         0  
61              
62             #-----------------------------------------------------------------------------
63              
64 0     0 0 0 sub get_extents { my ($self) = @_ ; return($self->{EXTENTS}) ; }
  0         0  
65              
66             #-----------------------------------------------------------------------------
67              
68 0     0 0 0 sub resize { my ($self, $reference_x, $reference_y, $new_x, $new_y) = @_ ; return(0, 0, $self->{WIDTH}, $self->{HEIGHT}) ; }
  0         0  
69              
70             #-----------------------------------------------------------------------------
71              
72       0 0   sub get_action_menu_entries { ; }
73              
74             #-----------------------------------------------------------------------------
75              
76 0     0 0 0 sub get_selection_action { 'move' ; }
77              
78             #-----------------------------------------------------------------------------
79              
80 0     0 0 0 sub get_colors { my ($self) = @_ ; return $self->{COLORS}{BACKGROUND}, $self->{COLORS}{FOREGROUND} ; }
  0         0  
81              
82             #-----------------------------------------------------------------------------
83              
84 0     0 0 0 sub set_background_color { my ($self, $background_color) = @_ ; $self->{COLORS}{BACKGROUND} = $background_color ; }
  0         0  
85              
86             #-----------------------------------------------------------------------------
87              
88 0     0 0 0 sub set_foreground_color { my ($self, $foreground_color) = @_ ; $self->{COLORS}{FOREGROUND} = $foreground_color ; }
  0         0  
89              
90             #-----------------------------------------------------------------------------
91              
92             sub set_colors
93             {
94 0     0 0 0 my ($self, $background_color, $foreground_color) = @_ ;
95              
96 0         0 $self->{COLORS}{BACKGROUND} = $background_color ;
97 0         0 $self->{COLORS}{FOREGROUND} = $foreground_color ;
98             }
99              
100             #-----------------------------------------------------------------------------
101              
102       0 0   sub get_text { ; }
103              
104             #-----------------------------------------------------------------------------
105              
106       0 0   sub set_text { ; }
107              
108             #-----------------------------------------------------------------------------
109              
110       0 0   sub edit { ; }
111              
112             #-----------------------------------------------------------------------------
113              
114       0 0   sub match_connector { ; }
115              
116             #-----------------------------------------------------------------------------
117              
118       0 0   sub get_connector_points { ; }
119              
120       0 0   sub get_connection_points { ; }
121              
122       0 0   sub get_extra_points { ; }
123              
124             #-----------------------------------------------------------------------------
125              
126       0 0   sub get_named_connection { ; }
127              
128             #-----------------------------------------------------------------------------
129              
130       0 0   sub move_connector { ; }
131              
132             #-----------------------------------------------------------------------------
133              
134       0 0   sub allow_border_connection { ; }
135              
136 0     0 0 0 sub is_border_connection_allowed { 0 }
137              
138             #-----------------------------------------------------------------------------
139              
140 169     169 0 301 sub is_autoconnect_enabled { my ($self) = @_ ; return ! $self->{AUTOCONNECT_DISABLED} ; }
  169         875  
141              
142 0     0 0 0 sub enable_autoconnect { my ($self, $enable) = @_ ; $self->{AUTOCONNECT_DISABLED} = !$enable ; }
  0         0  
143              
144             #-----------------------------------------------------------------------------
145              
146 0     0 0 0 sub is_optimize_enabled { my ($self) = @_ ; return ! $self->{OPTIMIZE_DISABLED} ; }
  0         0  
147              
148 0     0 0 0 sub enable_optimize { my ($self, $enable) = @_ ; $self->{OPTIMIZE_DISABLED} = !$enable ; }
  0         0  
149              
150             #-----------------------------------------------------------------------------
151              
152             sub set
153             {
154             # set fields in the hash
155              
156 457     457 0 2151 my ($self, %key_values) = @_ ;
157              
158 457         1555 while (my ($key, $value) = each %key_values)
159             {
160 3153         9494 $self->{$key} = ${value} ;
161             }
162              
163 457         1689 delete $self->{CACHE};
164             }
165              
166             #-----------------------------------------------------------------------------
167              
168             1 ;