File Coverage

blib/lib/Excel/Writer/XLSX/Format.pm
Criterion Covered Total %
statement 203 217 93.5
branch 132 154 85.7
condition 13 18 72.2
subroutine 30 32 93.7
pod 0 22 0.0
total 378 443 85.3


line stmt bran cond sub pod time code
1             package Excel::Writer::XLSX::Format;
2              
3             ###############################################################################
4             #
5             # Format - A class for defining Excel formatting.
6             #
7             #
8             # Used in conjunction with Excel::Writer::XLSX
9             #
10             # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
11             #
12             # Documentation after __END__
13             #
14              
15 1082     1082   16509 use 5.008002;
  1082         14323  
16 1082     1082   5773 use Exporter;
  1082         1930  
  1082         32911  
17 1082     1082   5159 use strict;
  1082         1963  
  1082         22447  
18 1082     1082   5163 use warnings;
  1082         2344  
  1082         28939  
19 1082     1082   6142 use Carp;
  1082         2312  
  1082         2487625  
20              
21              
22             our @ISA = qw(Exporter);
23             our $VERSION = '1.07';
24             our $AUTOLOAD;
25              
26              
27             ###############################################################################
28             #
29             # new()
30             #
31             # Constructor
32             #
33             sub new {
34              
35 2052     2052 0 33405 my $class = shift;
36              
37 2052         51087 my $self = {
38             _xf_format_indices => shift,
39             _dxf_format_indices => shift,
40             _xf_index => undef,
41             _dxf_index => undef,
42              
43             _num_format => 'General',
44             _num_format_index => 0,
45             _font_index => 0,
46             _has_font => 0,
47             _has_dxf_font => 0,
48             _font => 'Calibri',
49             _size => 11,
50             _bold => 0,
51             _italic => 0,
52             _color => 0x0,
53             _underline => 0,
54             _font_strikeout => 0,
55             _font_outline => 0,
56             _font_shadow => 0,
57             _font_script => 0,
58             _font_family => 2,
59             _font_charset => 0,
60             _font_scheme => 'minor',
61             _font_condense => 0,
62             _font_extend => 0,
63             _theme => 0,
64             _hyperlink => 0,
65             _xf_id => 0,
66              
67             _hidden => 0,
68             _locked => 1,
69              
70             _text_h_align => 0,
71             _text_wrap => 0,
72             _text_v_align => 0,
73             _text_justlast => 0,
74             _rotation => 0,
75              
76             _fg_color => 0x00,
77             _bg_color => 0x00,
78             _pattern => 0,
79             _has_fill => 0,
80             _has_dxf_fill => 0,
81             _fill_index => 0,
82             _fill_count => 0,
83              
84             _border_index => 0,
85             _has_border => 0,
86             _has_dxf_border => 0,
87             _border_count => 0,
88              
89             _bottom => 0,
90             _bottom_color => 0x0,
91             _diag_border => 0,
92             _diag_color => 0x0,
93             _diag_type => 0,
94             _left => 0,
95             _left_color => 0x0,
96             _right => 0,
97             _right_color => 0x0,
98             _top => 0,
99             _top_color => 0x0,
100              
101             _indent => 0,
102             _shrink => 0,
103             _merge_range => 0,
104             _reading_order => 0,
105             _just_distrib => 0,
106             _color_indexed => 0,
107             _font_only => 0,
108              
109             };
110              
111 2052         4565 bless $self, $class;
112              
113             # Set properties passed to Workbook::add_format()
114 2052 100       9551 $self->set_format_properties(@_) if @_;
115              
116 2052         5964 return $self;
117             }
118              
119              
120             ###############################################################################
121             #
122             # copy($format)
123             #
124             # Copy the attributes of another Excel::Writer::XLSX::Format object.
125             #
126             sub copy {
127 2     2 0 12 my $self = shift;
128 2         4 my $other = $_[0];
129              
130              
131 2 50       17 return unless defined $other;
132 2 50       11 return unless ( ref( $self ) eq ref( $other ) );
133              
134             # Store properties that we don't want over-ridden.
135 2         16 my $xf_index = $self->{_xf_index};
136 2         5 my $dxf_index = $self->{_dxf_index};
137 2         5 my $xf_format_indices = $self->{_xf_format_indices};
138 2         5 my $dxf_format_indices = $self->{_dxf_format_indices};
139 2         4 my $palette = $self->{_palette};
140              
141             # Copy properties.
142 2         50 %$self = %$other;
143              
144             # Restore original properties.
145 2         10 $self->{_xf_index} = $xf_index;
146 2         4 $self->{_dxf_index} = $dxf_index;
147 2         5 $self->{_xf_format_indices} = $xf_format_indices;
148 2         4 $self->{_dxf_format_indices} = $dxf_format_indices;
149 2         15 $self->{_palette} = $palette;
150             }
151              
152              
153             ###############################################################################
154             #
155             # get_align_properties()
156             #
157             # Return properties for an Style xf sub-element.
158             #
159             sub get_align_properties {
160              
161 1154     1154 0 2616 my $self = shift;
162              
163 1154         2377 my @align; # Attributes to return
164              
165             # Check if any alignment options in the format have been changed.
166             my $changed =
167             ( $self->{_text_h_align} != 0
168             || $self->{_text_v_align} != 0
169             || $self->{_indent} != 0
170             || $self->{_rotation} != 0
171             || $self->{_text_wrap} != 0
172             || $self->{_shrink} != 0
173 1154 100 100     25726 || $self->{_reading_order} != 0 ) ? 1 : 0;
174              
175 1154 100       6433 return unless $changed;
176              
177              
178              
179             # Indent is only allowed for horizontal left, right and distributed. If it
180             # is defined for any other alignment or no alignment has been set then
181             # default to left alignment.
182 45 100 100     179 if ( $self->{_indent}
      100        
      100        
183             && $self->{_text_h_align} != 1
184             && $self->{_text_h_align} != 3
185             && $self->{_text_h_align} != 7 )
186             {
187 1         2 $self->{_text_h_align} = 1;
188             }
189              
190             # Check for properties that are mutually exclusive.
191 45 100       128 $self->{_shrink} = 0 if $self->{_text_wrap};
192 45 100       124 $self->{_shrink} = 0 if $self->{_text_h_align} == 4; # Fill
193 45 100       125 $self->{_shrink} = 0 if $self->{_text_h_align} == 5; # Justify
194 45 100       127 $self->{_shrink} = 0 if $self->{_text_h_align} == 7; # Distributed
195 45 100       123 $self->{_just_distrib} = 0 if $self->{_text_h_align} != 7; # Distributed
196 45 100       110 $self->{_just_distrib} = 0 if $self->{_indent};
197              
198 45         88 my $continuous = 'centerContinuous';
199              
200 45 100       151 push @align, 'horizontal', 'left' if $self->{_text_h_align} == 1;
201 45 100       136 push @align, 'horizontal', 'center' if $self->{_text_h_align} == 2;
202 45 100       126 push @align, 'horizontal', 'right' if $self->{_text_h_align} == 3;
203 45 100       100 push @align, 'horizontal', 'fill' if $self->{_text_h_align} == 4;
204 45 100       99 push @align, 'horizontal', 'justify' if $self->{_text_h_align} == 5;
205 45 100       119 push @align, 'horizontal', $continuous if $self->{_text_h_align} == 6;
206 45 100       112 push @align, 'horizontal', 'distributed' if $self->{_text_h_align} == 7;
207              
208 45 100       109 push @align, 'justifyLastLine', 1 if $self->{_just_distrib};
209              
210             # Property 'vertical' => 'bottom' is a default. It sets applyAlignment
211             # without an alignment sub-element.
212 45 100       120 push @align, 'vertical', 'top' if $self->{_text_v_align} == 1;
213 45 100       97 push @align, 'vertical', 'center' if $self->{_text_v_align} == 2;
214 45 100       125 push @align, 'vertical', 'justify' if $self->{_text_v_align} == 4;
215 45 100       117 push @align, 'vertical', 'distributed' if $self->{_text_v_align} == 5;
216              
217 45 100       95 push @align, 'indent', $self->{_indent} if $self->{_indent};
218 45 100       117 push @align, 'textRotation', $self->{_rotation} if $self->{_rotation};
219              
220 45 100       110 push @align, 'wrapText', 1 if $self->{_text_wrap};
221 45 100       102 push @align, 'shrinkToFit', 1 if $self->{_shrink};
222              
223 45 100       103 push @align, 'readingOrder', 1 if $self->{_reading_order} == 1;
224 45 100       113 push @align, 'readingOrder', 2 if $self->{_reading_order} == 2;
225              
226 45         178 return $changed, @align;
227             }
228              
229              
230             ###############################################################################
231             #
232             # get_protection_properties()
233             #
234             # Return properties for an Excel XML element.
235             #
236             sub get_protection_properties {
237              
238 1154     1154 0 2485 my $self = shift;
239              
240 1154         2290 my @attribs;
241              
242 1154 100       4053 push @attribs, 'locked', 0 if !$self->{_locked};
243 1154 100       4387 push @attribs, 'hidden', 1 if $self->{_hidden};
244              
245 1154         3365 return @attribs;
246             }
247              
248              
249             ###############################################################################
250             #
251             # get_format_key()
252             #
253             # Returns a unique hash key for the Format object.
254             #
255             sub get_format_key {
256              
257 252     252 0 430 my $self = shift;
258              
259             my $key = join ':',
260             (
261             $self->get_font_key(), $self->get_border_key,
262             $self->get_fill_key(), $self->get_alignment_key(),
263             $self->{_num_format}, $self->{_locked},
264             $self->{_hidden}
265 252         806 );
266              
267 252         687 return $key;
268             }
269              
270             ###############################################################################
271             #
272             # get_font_key()
273             #
274             # Returns a unique hash key for a font. Used by Workbook.
275             #
276             sub get_font_key {
277              
278 1372     1372 0 5864 my $self = shift;
279              
280             my $key = join ':', (
281             $self->{_bold},
282             $self->{_color},
283             $self->{_font_charset},
284             $self->{_font_family},
285             $self->{_font_outline},
286             $self->{_font_script},
287             $self->{_font_shadow},
288             $self->{_font_strikeout},
289             $self->{_font},
290             $self->{_italic},
291             $self->{_size},
292             $self->{_underline},
293             $self->{_theme},
294              
295 1372         13647 );
296              
297 1372         8353 return $key;
298             }
299              
300              
301             ###############################################################################
302             #
303             # get_border_key()
304             #
305             # Returns a unique hash key for a border style. Used by Workbook.
306             #
307             sub get_border_key {
308              
309 1405     1405 0 2607 my $self = shift;
310              
311             my $key = join ':', (
312             $self->{_bottom},
313             $self->{_bottom_color},
314             $self->{_diag_border},
315             $self->{_diag_color},
316             $self->{_diag_type},
317             $self->{_left},
318             $self->{_left_color},
319             $self->{_right},
320             $self->{_right_color},
321             $self->{_top},
322             $self->{_top_color},
323              
324 1405         8466 );
325              
326 1405         4142 return $key;
327             }
328              
329              
330             ###############################################################################
331             #
332             # get_fill_key()
333             #
334             # Returns a unique hash key for a fill style. Used by Workbook.
335             #
336             sub get_fill_key {
337              
338 1372     1372 0 2683 my $self = shift;
339              
340             my $key = join ':', (
341             $self->{_pattern},
342             $self->{_bg_color},
343             $self->{_fg_color},
344              
345 1372         4657 );
346              
347 1372         4101 return $key;
348             }
349              
350              
351             ###############################################################################
352             #
353             # get_alignment_key()
354             #
355             # Returns a unique hash key for alignment formats.
356             #
357             sub get_alignment_key {
358              
359 252     252 0 466 my $self = shift;
360              
361             my $key = join ':', (
362             $self->{_text_h_align},
363             $self->{_text_v_align},
364             $self->{_indent},
365             $self->{_rotation},
366             $self->{_text_wrap},
367             $self->{_shrink},
368             $self->{_reading_order},
369              
370 252         1481 );
371              
372 252         1060 return $key;
373             }
374              
375              
376             ###############################################################################
377             #
378             # get_xf_index()
379             #
380             # Returns the index used by Worksheet->_XF()
381             #
382             sub get_xf_index {
383 519     519 0 808 my $self = shift;
384              
385 519 100       1275 if ( defined $self->{_xf_index} ) {
386 286         663 return $self->{_xf_index};
387             }
388             else {
389 233         744 my $key = $self->get_format_key();
390 233         370 my $indices_href = ${ $self->{_xf_format_indices} };
  233         503  
391              
392 233 100       759 if ( exists $indices_href->{$key} ) {
393 8         22 return $indices_href->{$key};
394             }
395             else {
396 225         796 my $index = 1 + scalar keys %$indices_href;
397 225         615 $indices_href->{$key} = $index;
398 225         679 $self->{_xf_index} = $index;
399 225         752 return $index;
400             }
401             }
402             }
403              
404              
405             ###############################################################################
406             #
407             # get_dxf_index()
408             #
409             # Returns the index used by Worksheet->_XF()
410             #
411             sub get_dxf_index {
412 37     37 0 91 my $self = shift;
413              
414 37 100       129 if ( defined $self->{_dxf_index} ) {
415 18         59 return $self->{_dxf_index};
416             }
417             else {
418 19         72 my $key = $self->get_format_key();
419 19         42 my $indices_href = ${ $self->{_dxf_format_indices} };
  19         41  
420              
421 19 50       108 if ( exists $indices_href->{$key} ) {
422 0         0 return $indices_href->{$key};
423             }
424             else {
425 19         67 my $index = scalar keys %$indices_href;
426 19         56 $indices_href->{$key} = $index;
427 19         41 $self->{_dxf_index} = $index;
428 19         105 return $index;
429             }
430             }
431             }
432              
433              
434             ###############################################################################
435             #
436             # _get_color()
437             #
438             # Used in conjunction with the set_xxx_color methods to convert a color
439             # string into a number. Color range is 0..63 but we will restrict it
440             # to 8..63 to comply with Gnumeric. Colors 0..7 are repeated in 8..15.
441             #
442             sub _get_color {
443              
444 4302     4302   23866 my %colors = (
445             aqua => 0x0F,
446             cyan => 0x0F,
447             black => 0x08,
448             blue => 0x0C,
449             brown => 0x10,
450             magenta => 0x0E,
451             fuchsia => 0x0E,
452             gray => 0x17,
453             grey => 0x17,
454             green => 0x11,
455             lime => 0x0B,
456             navy => 0x12,
457             orange => 0x35,
458             pink => 0x21,
459             purple => 0x14,
460             red => 0x0A,
461             silver => 0x16,
462             white => 0x09,
463             yellow => 0x0D,
464             );
465              
466             # Return the default color if undef,
467 4302 50       7240 return 0x00 unless defined $_[0];
468              
469             # Return RGB style colors for processing later.
470 4302 100       7311 if ( $_[0] =~ m/^#[0-9A-F]{6}$/i ) {
471 22         143 return $_[0];
472             }
473              
474             # or the color string converted to an integer,
475 4280 100       7996 return $colors{ lc( $_[0] ) } if exists $colors{ lc( $_[0] ) };
476              
477             # or the default color if string is unrecognised,
478 4164 50       8915 return 0x00 if ( $_[0] =~ m/\D/ );
479              
480             # or an index < 8 mapped into the correct range,
481 4164 50       6460 return $_[0] + 8 if $_[0] < 8;
482              
483             # or the default color if arg is outside range,
484 4164 100       15039 return 0x00 if $_[0] > 63;
485              
486             # or an integer in the valid range
487 4         27 return $_[0];
488             }
489              
490              
491             ###############################################################################
492             #
493             # set_type()
494             #
495             # Set the XF object type as 0 = cell XF or 0xFFF5 = style XF.
496             #
497             sub set_type {
498              
499 0     0 0 0 my $self = shift;
500 0         0 my $type = $_[0];
501              
502 0 0 0     0 if (defined $_[0] and $_[0] eq 0) {
503 0         0 $self->{_type} = 0x0000;
504             }
505             else {
506 0         0 $self->{_type} = 0xFFF5;
507             }
508             }
509              
510              
511             ###############################################################################
512             #
513             # set_align()
514             #
515             # Set cell alignment.
516             #
517             sub set_align {
518              
519 34     34 0 66 my $self = shift;
520 34         57 my $location = $_[0];
521              
522 34 50       83 return if not defined $location; # No default
523 34 50       119 return if $location =~ m/\d/; # Ignore numbers
524              
525 34         74 $location = lc( $location );
526              
527 34 100       122 $self->set_text_h_align( 1 ) if $location eq 'left';
528 34 50       83 $self->set_text_h_align( 2 ) if $location eq 'centre';
529 34 100       143 $self->set_text_h_align( 2 ) if $location eq 'center';
530 34 100       82 $self->set_text_h_align( 3 ) if $location eq 'right';
531 34 100       77 $self->set_text_h_align( 4 ) if $location eq 'fill';
532 34 100       96 $self->set_text_h_align( 5 ) if $location eq 'justify';
533 34 100       81 $self->set_text_h_align( 6 ) if $location eq 'center_across';
534 34 50       75 $self->set_text_h_align( 6 ) if $location eq 'centre_across';
535 34 50       111 $self->set_text_h_align( 6 ) if $location eq 'merge'; # Legacy.
536 34 100       81 $self->set_text_h_align( 7 ) if $location eq 'distributed';
537 34 50       83 $self->set_text_h_align( 7 ) if $location eq 'equal_space'; # S::PE.
538 34 100       101 $self->set_text_h_align( 7 ) if $location eq 'justify_distributed';
539              
540 34 100       95 $self->{_just_distrib} = 1 if $location eq 'justify_distributed';
541              
542 34 100       97 $self->set_text_v_align( 1 ) if $location eq 'top';
543 34 50       74 $self->set_text_v_align( 2 ) if $location eq 'vcentre';
544 34 100       112 $self->set_text_v_align( 2 ) if $location eq 'vcenter';
545 34 100       83 $self->set_text_v_align( 3 ) if $location eq 'bottom';
546 34 100       74 $self->set_text_v_align( 4 ) if $location eq 'vjustify';
547 34 100       91 $self->set_text_v_align( 5 ) if $location eq 'vdistributed';
548 34 50       175 $self->set_text_v_align( 5 ) if $location eq 'vequal_space'; # S::PE.
549             }
550              
551              
552             ###############################################################################
553             #
554             # set_valign()
555             #
556             # Set vertical cell alignment. This is required by the set_properties() method
557             # to differentiate between the vertical and horizontal properties.
558             #
559             sub set_valign {
560              
561 3     3 0 6 my $self = shift;
562 3         11 $self->set_align( @_ );
563             }
564              
565              
566             ###############################################################################
567             #
568             # set_center_across()
569             #
570             # Implements the Excel5 style "merge".
571             #
572             sub set_center_across {
573              
574 1     1 0 6 my $self = shift;
575              
576 1         8 $self->set_text_h_align( 6 );
577             }
578              
579              
580             ###############################################################################
581             #
582             # set_merge()
583             #
584             # This was the way to implement a merge in Excel5. However it should have been
585             # called "center_across" and not "merge".
586             # This is now deprecated. Use set_center_across() or better merge_range().
587             #
588             #
589             sub set_merge {
590              
591 1     1 0 2 my $self = shift;
592              
593 1         8 $self->set_text_h_align( 6 );
594             }
595              
596              
597             ###############################################################################
598             #
599             # set_bold()
600             #
601             #
602             sub set_bold {
603              
604 79     79 0 202 my $self = shift;
605 79 100       278 my $bold = defined $_[0] ? $_[0] : 1;
606              
607 79 50       561 $self->{_bold} = $bold ? 1 : 0;
608             }
609              
610              
611             ###############################################################################
612             #
613             # set_border($style)
614             #
615             # Set cells borders to the same style
616             #
617             sub set_border {
618              
619 1     1 0 2 my $self = shift;
620 1         2 my $style = $_[0];
621              
622 1         7 $self->set_bottom( $style );
623 1         6 $self->set_top( $style );
624 1         6 $self->set_left( $style );
625 1         5 $self->set_right( $style );
626             }
627              
628              
629             ###############################################################################
630             #
631             # set_border_color($color)
632             #
633             # Set cells border to the same color
634             #
635             sub set_border_color {
636              
637 0     0 0 0 my $self = shift;
638 0         0 my $color = $_[0];
639              
640 0         0 $self->set_bottom_color( $color );
641 0         0 $self->set_top_color( $color );
642 0         0 $self->set_left_color( $color );
643 0         0 $self->set_right_color( $color );
644             }
645              
646              
647             ###############################################################################
648             #
649             # set_rotation($angle)
650             #
651             # Set the rotation angle of the text. An alignment property.
652             #
653             sub set_rotation {
654              
655 7     7 0 11 my $self = shift;
656 7         11 my $rotation = $_[0];
657              
658             # Argument should be a number
659 7 50       47 return if $rotation !~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/;
660              
661             # The arg type can be a double but the Excel dialog only allows integers.
662 7         15 $rotation = int $rotation;
663              
664 7 100 33     38 if ( $rotation == 270 ) {
    50          
665 1         2 $rotation = 255;
666             }
667             elsif ( $rotation >= -90 and $rotation <= 90 ) {
668 6 100       17 $rotation = -$rotation + 90 if $rotation < 0;
669             }
670             else {
671 0         0 carp "Rotation $rotation outside range: -90 <= angle <= 90";
672 0         0 $rotation = 0;
673             }
674              
675 7         30 $self->{_rotation} = $rotation;
676             }
677              
678              
679             ###############################################################################
680             #
681             # set_hyperlink()
682             #
683             # Set the properties for the hyperlink style. This isn't a public method. To
684             # be fixed when styles are supported.
685             #
686             sub set_hyperlink {
687              
688 853     853 0 1995 my $self = shift;
689 853         1912 my $hyperlink = shift;
690              
691 853         2190 $self->{_xf_id} = 1;
692              
693 853         7088 $self->set_underline( 1 );
694 853         7416 $self->set_theme( 10 );
695 853         4210 $self->{_hyperlink} = $hyperlink;
696             }
697              
698              
699             ###############################################################################
700             #
701             # set_format_properties()
702             #
703             # Convert hashes of properties to method calls.
704             #
705             sub set_format_properties {
706              
707 2015     2015 0 3360 my $self = shift;
708              
709 2015         5822 my %properties = @_; # Merge multiple hashes into one
710              
711 2015         8560 while ( my ( $key, $value ) = each( %properties ) ) {
712              
713             # Strip leading "-" from Tk style properties e.g. -color => 'red'.
714 2219         5033 $key =~ s/^-//;
715              
716             # Create a sub to set the property.
717 2219         3310 my $sub = \&{"set_$key"};
  2219         9872  
718 2219         9067 $sub->( $self, $value );
719             }
720             }
721              
722             # Renamed rarely used set_properties() to set_format_properties() to avoid
723             # confusion with Workbook method of the same name. The following acts as an
724             # alias for any code that uses the old name.
725             *set_properties = *set_format_properties;
726              
727              
728             ###############################################################################
729             #
730             # AUTOLOAD. Deus ex machina.
731             #
732             # Dynamically create set methods that aren't already defined.
733             #
734             sub AUTOLOAD {
735              
736 4766     4766   61239 my $self = shift;
737              
738             # Ignore calls to DESTROY
739 4766 100       237311 return if $AUTOLOAD =~ /::DESTROY$/;
740              
741             # Check for a valid method names, i.e. "set_xxx_yyy".
742 2714 50       14321 $AUTOLOAD =~ /.*::set(\w+)/ or die "Unknown method: $AUTOLOAD\n";
743              
744             # Match the attribute, i.e. "_xxx_yyy".
745 2714         7186 my $attribute = $1;
746              
747             # Check that the attribute exists
748 2714 50       9926 exists $self->{$attribute} or die "Unknown method: $AUTOLOAD\n";
749              
750             # The attribute value
751 2714         4090 my $value;
752              
753              
754             # There are two types of set methods: set_property() and
755             # set_property_color(). When a method is AUTOLOADED we store a new anonymous
756             # sub in the appropriate slot in the symbol table. The speeds up subsequent
757             # calls to the same method.
758             #
759 1082     1082   9412 no strict 'refs'; # To allow symbol table hackery
  1082         2231  
  1082         220751  
760              
761 2714 100       7050 if ( $AUTOLOAD =~ /.*::set\w+color$/ ) {
762              
763             # For "set_property_color" methods
764 40         165 $value = _get_color( $_[0] );
765              
766 40         155 *{$AUTOLOAD} = sub {
767 17     17   30 my $self = shift;
768              
769 17         45 $self->{$attribute} = _get_color( $_[0] );
770 40         165 };
771             }
772             else {
773              
774 2674         4183 $value = $_[0];
775 2674 100       5548 $value = 1 if not defined $value; # The default value is always 1
776              
777 2674         9721 *{$AUTOLOAD} = sub {
778 265     265   421 my $self = shift;
779 265         396 my $value = shift;
780              
781 265 50       607 $value = 1 if not defined $value;
782 265         846 $self->{$attribute} = $value;
783 2674         9272 };
784             }
785              
786              
787 2714         14500 $self->{$attribute} = $value;
788             }
789              
790              
791             1;
792              
793              
794             __END__