File Coverage

lib/MKDoc/Text/Structured/Block.pm
Criterion Covered Total %
statement 51 51 100.0
branch 10 10 100.0
condition 13 14 92.8
subroutine 10 10 100.0
pod 0 3 0.0
total 84 88 95.4


line stmt bran cond sub pod time code
1             package MKDoc::Text::Structured::Block;
2 20     20   9202 use MKDoc::Text::Structured::P;
  20         49  
  20         575  
3 20     20   10431 use MKDoc::Text::Structured::H1;
  20         52  
  20         573  
4 20     20   8154 use MKDoc::Text::Structured::H2;
  20         52  
  20         519  
5 20     20   8191 use MKDoc::Text::Structured::H3;
  20         46  
  20         597  
6 20     20   112 use base qw /MKDoc::Text::Structured::Base/;
  20         35  
  20         12369  
7 20     20   117 use warnings;
  20         40  
  20         428  
8 20     20   106 use strict;
  20         33  
  20         8157  
9              
10              
11             sub new
12             {
13 247     247 0 315 my $class = shift;
14 247         383 my $line = shift;
15 247 100       1013 return if ($line =~ /^\s*$/);
16 205         1530 return bless {}, $class;
17             }
18              
19              
20             sub is_ok
21             {
22 132     132 0 194 my $self = shift;
23 132         228 my $line = shift;
24 132   100     523 my $obj = MKDoc::Text::Structured::Factory->new ($line) || return;
25 114 100       1209 return 1 if (ref $obj eq ref $self);
26 2         7 return;
27             }
28              
29              
30             sub process
31             {
32 93     93 0 154 my $self = shift;
33 93         123 my @lines = @{$self->{lines}};
  93         274  
34              
35             # =========
36             # Heading 1
37             # =========
38             @lines > 1 and
39             $lines[0] =~ /^==/ and
40 93 100 100     421 $lines[-1] =~ /^==/ and do {
      66        
41 1         2 shift (@lines);
42 1         1 pop (@lines);
43 1         6 $self->{lines} = \@lines;
44 1         4 bless $self, 'MKDoc::Text::Structured::H1';
45 1         6 return $self->process (@_);
46             };
47              
48             # Heading 2
49             # =========
50             @lines > 1 and
51 92 100 100     624 $lines[-1] =~ /^==/ and do {
52 5         10 pop (@lines);
53 5         15 $self->{lines} = \@lines;
54 5         36 bless $self, 'MKDoc::Text::Structured::H2';
55 5         30 return $self->process (@_);
56             };
57              
58             # Heading 3
59             # ---------
60             @lines > 1 and
61 87 100 100     441 $lines[-1] =~ /^--/ and do {
62 3         14 pop (@lines);
63 3         6 $self->{lines} = \@lines;
64 3         12 bless $self, 'MKDoc::Text::Structured::H3';
65 3         15 return $self->process (@_);
66             };
67              
68             # normal, boring paragraph
69 84         262 bless $self, 'MKDoc::Text::Structured::P';
70 84         319 return $self->process (@_);
71             }
72              
73              
74             1;
75              
76             __END__