| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 38 | 28 | ▶ | return $_PARSER_FOR{$format} if $_PARSER_FOR{$format}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 39 | 11 | ▶ | my $pkg = __PACKAGE__ . '::' . ($format eq 'html' ? 'HTML' : ucfirst $format); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 40 | 11 | ▶ | eval "require $pkg; 1" or die $@; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 41 | 11 | ▶ | return $_PARSER_FOR{$format} = $pkg->can('parser') | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$pkg->can('parser') || croak("No parser() function defind in $pkg")
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')
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 60 | 26 | ▶ | croak "$file does not exist" unless -e $file && !-d _; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $file and not -d _
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 _
| |||||||||||||||||||||||||||||||||||
| 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
$p{'options'} || []
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
Truth table100%2/2
A
A= $p{'options'}
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
$p->{"format"} or $self->guess_format($p->{"file"})
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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | 15 | return; | |||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||||||||