Markup.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 75.0% 15 / 20 Conditioncond 68.7% 11 / 16 MC/DCmcdc 44.4% 4 / 9 Subroutinesub 100% 16 / 16 Podpod 100% 8 / 8 totaltotal 86.9% 107 / 123 CC 18 SCAR 12.9
CC
18
Cov
88%
parse
7.3
_parser_for
6.1
_get_parser
3.0
CRAP 3.6
« Markup/Asciidoc.pm ↑ Summary Markup/Rest.pm »
1 package Text::Markup;
2  
3 2 ▶use 5.8.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Text::Markup;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Text::Markup::None;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '0.43';
11  
12 2 my %_PARSER_FOR;
13 2 my %REGEX_FOR = (
14 html => qr{x?html?},
15 markdown => qr{m(?:d(?:own)?|kdn?|arkdown)},
16 multimarkdown => qr{mm(?:d(?:own)?|kdn?|arkdown)},
17 pod => qr{p(?:od|m|l)},
18 textile => qr{textile},
19 trac => qr{tra?c},
20 mediawiki => qr{(?:m(?:edia)?)?wiki},
21 rest => qr{re?st},
22 asciidoc => qr{a(?:sc(?:iidoc)?|doc)?},
23 bbcode => qr{bb(?:code)?},
24 creole => qr{creole},
25 );
26  
27 21 ▶sub register {
Subroutine register: called CC=2 SCAR=7.0
Pod documented
28 21 my ($class, $name, $regex) = @_;
29 21 my $pkg = caller;
30 21 $REGEX_FOR{$name} = $regex;
31 21 ▶ $_PARSER_FOR{$name} = $pkg->can('parser')
Branch: 1 branch
BranchTrueFalseTotal
$_PARSER_FOR{$name} = $pkg->can("parser") or croak("No parser() function defind in $pkg") 21 0 21
32 or croak "No parser() function defind in $pkg";
33 }
34  
35 30 ▶sub _parser_for {
Subroutine _parser_for: called CC=6 SCAR=18.0
36 30 my ($self, $format) = @_;
37 30 ▶ return Text::Markup::None->can('parser') unless $format;
Branch: 1 branch
BranchTrueFalseTotal
unless $format 2 28 30
38 28 ▶ return $_PARSER_FOR{$format} if $_PARSER_FOR{$format};
Branch: 1 branch
BranchTrueFalseTotal
if $_PARSER_FOR{$format} 17 11 28
39 11 ▶ my $pkg = __PACKAGE__ . '::' . ($format eq 'html' ? 'HTML' : ucfirst $format);
Branch: 1 branch
BranchTrueFalseTotal
$format eq 'html' ? : 1 10 11
40 11 ▶ eval "require $pkg; 1" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $pkg; 1" or die $@ 11 0 11
41 11 ▶ return $_PARSER_FOR{$format} = $pkg->can('parser')
Condition50%1/2
$pkg->can('parser') || croak("No parser() function defind in $pkg")
l!l
110
MC/DC0%0/1
$pkg->can('parser') || croak("No parser() function defind in $pkg")
$pkg->can('parser')
Truth table50%1/2
A
A= $pkg->can('parser')
Aresult
11
00
42 || croak "No parser() function defind in $pkg";
43 }
44  
45 14 ▶sub formats {
Subroutine formats: called CC=1 SCAR=0.0
Pod documented
46 14 sort keys %REGEX_FOR;
47 }
48  
49 2 ▶sub format_matchers { %REGEX_FOR }
Subroutine format_matchers: called CC=1 SCAR=0.0
Pod documented
50  
51 12 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
52 12 my $class = shift;
53 12 bless { default_encoding => 'UTF-8', @_ } => $class;
54 }
55  
56 26 ▶sub parse {
Subroutine parse: called CC=6 SCAR=19.9
Pod documented
57 26 my $self = shift;
58 26 my %p = @_;
59 26 ▶ my $file = $p{file} or croak "No file parameter passed to parse()";
Branch: 1 branch
BranchTrueFalseTotal
my $file = $p{"file"} or croak("No file parameter passed to parse()") 26 0 26
60 26 ▶ croak "$file does not exist" unless -e $file && !-d _;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file and not -d _ 0 26 26
Condition33%1/3
-e $file and not -d _
!ll&&!rl&&r
0026
MC/DC0%0/2
-e $file and not -d _
-e $file not -d _
Truth table33%1/3
A and not(B)
A= -e $fileB= not -d _
ABresult
0X0
100
111
61  
62 26 my $parser = $self->_get_parser(\%p);
63 return $parser->(
64 $file,
65 $p{encoding} || $self->default_encoding,
66 26 ▶ $p{options} || [],
Condition60%3/5
$p{'encoding'} || $self->default_encoding
l!l&&r!l&&!r
0260
$p{'options'} || []
l!l
323
MC/DC0%0/2
$p{'encoding'} || $self->default_encoding
$p{'encoding'} $self->default_encoding
MC/DC100%1/1
$p{'options'} || []
$p{'options'}
Truth table33%1/3
A || B
A= $p{'encoding'}B= $self->default_encoding
ABresult
1X1
011
000
Truth table100%2/2
A
A= $p{'options'}
Aresult
11
00
67 );
68 }
69  
70 8 ▶sub default_format {
Subroutine default_format: called CC=2 SCAR=6.9
Pod documented
71 8 my $self = shift;
72 8 ▶ return $self->{default_format} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 5 3 8
73 3 $self->{default_format} = shift;
74 }
75  
76 26 ▶sub default_encoding {
Subroutine default_encoding: called CC=2 SCAR=8.1
Pod documented
77 26 my $self = shift;
78 26 ▶ return $self->{default_encoding} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 26 0 26
79 0 $self->{default_encoding} = shift;
80 }
81  
82 30 ▶sub _get_parser {
Subroutine _get_parser: called CC=3 SCAR=11.0
83 30 my ($self, $p) = @_;
84 my $format = $p->{format}
85 || $self->guess_format($p->{file})
86 30 ▶ || $self->default_format;
Condition100%6/6
$p->{'format'} || $self->guess_format($p->{'file'}) || $self->default_format
l!l&&r!l&&!r
2712
$p->{"format"} or $self->guess_format($p->{"file"})
l!l&&r!l&&!r
2613
MC/DC100%3/3
$p->{'format'} || $self->guess_format($p->{'file'}) || $self->default_format
$p->{"format"} $self->guess_format($p->{"file"}) $self->default_format
Truth table100%4/4
A or B || C
A= $p->{"format"}B= $self->guess_format($p->{"file"})C= $self->default_format
ABCresult
1XX1
01X1
0011
0000
87  
88 30 return $self->_parser_for($format);
89 }
90  
91 56 ▶sub guess_format {
Subroutine guess_format: called CC=3 SCAR=11.0
Pod documented
92 56 my ($self, $file) = @_;
93 56 for my $format (keys %REGEX_FOR) {
94 423 ▶ return $format if $file =~ qr{[.]$REGEX_FOR{$format}$};
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ qr/[.]$REGEX_FOR{$format}$/ 41 382 423
95 }
96 15 return;
97 }
98  
99 2 1;
100 __END__
« Markup/Asciidoc.pm ↑ Summary Markup/Rest.pm »