File Coverage

lib/HTML/FormWidgets/Label.pm
Criterion Covered Total %
statement 23 31 74.1
branch 4 8 50.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 34 46 73.9


line stmt bran cond sub pod time code
1             package HTML::FormWidgets::Label;
2              
3 1     1   601 use strict;
  1         2  
  1         40  
4 1     1   4 use warnings;
  1         1  
  1         26  
5 1     1   4 use parent 'HTML::FormWidgets';
  1         0  
  1         5  
6              
7             __PACKAGE__->mk_accessors( qw( dropcap ) );
8              
9             sub init {
10 5     5 1 8    my ($self, $args) = @_;
11              
12 5         19    $self->class ( 'label_text' );
13 5         32    $self->container( 0 );
14 5         26    $self->dropcap ( 0 );
15 5         30    $self->text ( undef );
16 5         23    return;
17             }
18              
19             sub render_field {
20 5     5 1 8    my ($self, $args) = @_; my $text = $self->text;
  5         13  
21              
22 5 50       21    defined $text or return; $text =~ s{ \A \n }{}msx;
  5         10  
23              
24 5 50       11    if ($self->dropcap) {
25 0         0       my $markup;
26              
27 0 0       0       if ($text =~ m{ \A (\<[A-Za-z0-9]+\>) }mx) {
28 0         0          $markup = $1;
29 0         0          $markup .= $self->hacc->span( { class => q(dropcap) },
30                                                    substr $text, length $1, 1 );
31 0         0          $markup .= substr $text, (length $1) + 1;
32                   }
33                   else {
34 0         0          $markup = $self->hacc->span( { class => q(dropcap) },
35                                                    substr $text, 0, 1 );
36 0         0          $markup .= substr $text, 1;
37                   }
38              
39 0         0       $text = $markup;
40                }
41              
42 5 100       29    $args = { class => $self->class }; $self->id and $args->{id} = $self->id;
  5         24  
43              
44 5         28    return $self->hacc->span( $args, $text );
45             }
46              
47             1;
48              
49             # Local Variables:
50             # mode: perl
51             # tab-width: 3
52             # End:
53