File Coverage

blib/lib/Text/Label/Prepender.pm
Criterion Covered Total %
statement 26 26 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 33 35 94.2


line stmt bran cond sub pod time code
1             package Text::Label::Prepender;
2              
3 1     1   9573 use 5.006;
  1         4  
  1         45  
4 1     1   7 use strict;
  1         2  
  1         292  
5 1     1   8 use warnings;
  1         7  
  1         525  
6              
7             require Exporter;
8              
9             our @ISA = qw(Exporter);
10              
11             # Items to export into callers namespace by default. Note: do not export
12             # names by default without a very good reason. Use EXPORT_OK instead.
13             # Do not simply export all your public functions/methods/constants.
14              
15             # This allows declaration use Text::Label::Prepender ':all';
16             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
17             # will save memory.
18             our %EXPORT_TAGS = ( 'all' => [ qw(
19            
20             ) ] );
21              
22             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
23              
24             our @EXPORT = qw(
25            
26             );
27             our $VERSION = '1.0';
28              
29              
30             # Preloaded methods go here.
31              
32             #
33             # the object constructor (simplistic version)
34             #
35              
36             my $LABEL = 0;
37             my $SEP = 1;
38             my $LABEL_CHAR = 2;
39             my $LABEL_RE = 3;
40              
41             sub new {
42              
43 1     1 0 106 my $pkg = shift;
44 1         7 my %args = @_;
45 1         3 my $self = [];
46 1         5 my $default = { initial_label => '', separator => '', label_char => ':' };
47              
48 1         3 $self->[$LABEL] = $args{initial_label};
49 1         3 $self->[$SEP] = $args{separator};
50 1         3 $self->[$LABEL_CHAR] = $args{label_char};
51              
52 1         2 my $tmp = $self->[$LABEL_CHAR];
53            
54 1         24 $self->[$LABEL_RE] = qr/(.*)$tmp\s*$/;
55              
56 1         80 warn $self->[$LABEL_RE];
57              
58 1         3 bless($self); # but see below (says perldoc perltoot)
59 1         8 return $self;
60             }
61              
62             sub process {
63              
64 12     12 0 248 my ($self,$line) = @_;
65              
66 12 100       63 if ($line =~ /$self->[$LABEL_RE]/) {
67              
68 2         6 $self->[$LABEL] = $1;
69              
70 2         7 return undef;
71              
72             } else {
73              
74 10         43 my @O =
75            
76             return join $self->[$SEP], ($self->[$LABEL], $line);
77              
78             }
79             }
80              
81              
82             1;
83             __END__