blib/lib/Text/Markup/Any.pm

filter: Statementstmt 85.1% 46 / 54 Branchbran 53.5% 15 / 28 Conditioncond 37.5% 3 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 4 totaltotal 68.8% 75 / 109 CC 18 SCAR 23.7
CC
18
Cov
71%
new
19.0
adaptor
12.5
markupper
2.0
CRAP 10.7
↑ Summary
1 package Text::Markup::Any;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 our $VERSION = '0.04';
6  
7 3 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Class::Load qw/load_class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 our @EXPORT = qw/markupper/;
11  
12 3 my $markdown = {markup_method => 'markdown'};
13 our %MODULES = (
14 'Text::Markdown' => $markdown,
15 'Text::MultiMarkdown' => $markdown,
16 'Text::Markdown::Discount' => $markdown,
17 'Text::Markdown::GitHubAPI' => $markdown,
18 'Text::Markdown::Hoedown' => {
19 class => 'Text::Markdown::Hoedown::Markdown',
20 markup_method => 'render',
21 1 ▶ args => sub { [0, 16, Text::Markdown::Hoedown::Renderer::HTML->new(0, 99)] },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 3 deref => 1,
23 },
24 'Text::Xatena' => {markup_method => 'format'},
25 'Text::Textile' => {markup_method => 'process'},
26 );
27  
28 4 ▶sub new {
Subroutine new: called CC=8 SCAR=29.4
Pod undocumented
29 4 my ($pkg, $class, @args) = @_;
30  
31 4 my $args;
32 4 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 4 4
33 0 ▶ $args = ref $args[0] ? $args[0] : {@args};
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] ? : 0 0 0
34 }
35  
36 4 ▶ my $info = $MODULES{$class}
Branch: 1 branch
BranchTrueFalseTotal
my $info = $Text::Markup::Any::MODULES{$class} or die "no configuration found: $class. You want to use $class, directory call $pkg->adaptor constractor." 4 0 4
37 or die "no configuration found: $class. You want to use $class, directory call $pkg->adaptor constractor.";
38  
39 4 ▶ if ($args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args) 0 4 4
40 0 ▶ if ($info->{args} && ref($info->{args}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{'args'} and ref $info->{'args'} eq 'HASH') { } 0 0 0
Condition0%0/3
$info->{"args"} and ref $info->{"args"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$info->{"args"} and ref $info->{"args"} eq "HASH"
$info->{"args"} ref $info->{"args"} eq "HASH"
Truth table0%0/3
A and B
A= $info->{"args"}B= ref $info->{"args"} eq "HASH"
ABresult
0X0
100
111
41 $info->{args} = {
42 0 %{ $info->{args} },
43 %$args,
44 };
45 }
46 else {
47 0 $info->{args} = $args;
48 }
49 }
50  
51 4 ▶ load_class($class) if $info->{class};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"class"} 1 3 4
52 4 $pkg->adaptor(
53 class => $class,
54 %$info,
55 );
56 }
57  
58 # taken from Ark::Models
59 4 ▶sub adaptor {
Subroutine adaptor: called CC=10 SCAR=25.3
Pod undocumented
60 4 my ($pkg, %info) = @_;
61  
62 4 ▶ my $class = $info{class} or die q{Required class parameter};
Branch: 1 branch
BranchTrueFalseTotal
my $class = $info{"class"} or die "Required class parameter" 4 0 4
63 4 ▶ my $markup_method = $info{markup_method} or die q{Required markup_method parameter};
Branch: 1 branch
BranchTrueFalseTotal
my $markup_method = $info{"markup_method"} or die "Required markup_method parameter" 4 0 4
64 4 ▶ my $constructor = $info{constructor} || 'new';
Condition50%1/2
$info{'constructor'} || 'new'
l!l
04
MC/DC0%0/1
$info{'constructor'} || 'new'
$info{'constructor'}
Truth table50%1/2
A
A= $info{'constructor'}
Aresult
11
00
65  
66 4 load_class($class);
67 4 ▶ $info{args} = $info{args}->() if ref $info{args} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $info{"args"} eq "CODE" 1 3 4
68  
69 4 my $instance;
70 4 ▶ if ($info{deref} and my $args = $info{args}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($info{'deref'} and my $args = $info{'args'}) { } 1 3 4
elsif ($info{'args'}) { } 0 3 3
Condition66%2/3
$info{"deref"} and my $args = $info{"args"}
!ll&&!rl&&r
301
MC/DC50%1/2
$info{"deref"} and my $args = $info{"args"}
$info{"deref"} my $args = $info{"args"}
Truth table66%2/3
A and B
A= $info{"deref"}B= my $args = $info{"args"}
ABresult
0X0
100
111
71 1 ▶ if (ref($args) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $args eq 'HASH') { } 0 1 1
elsif (ref $args eq 'ARRAY') { } 1 0 1
72 0 $instance = $class->$constructor(%$args);
73 }
74 elsif (ref($args) eq 'ARRAY') {
75 1 $instance = $class->$constructor(@$args);
76 }
77 else {
78 0 die qq{Couldn't dereference: $args};
79 }
80 }
81 elsif ($info{args}) {
82 0 $instance = $class->$constructor($info{args});
83 }
84 else {
85 3 $instance = $class->$constructor;
86 }
87  
88 4 bless {
89 _instance => $instance,
90 _markup_method => $markup_method,
91 }, $pkg;
92 }
93  
94 4 ▶sub markup {
Subroutine markup: called CC=1 SCAR=0.0
Pod undocumented
95 4 my ($self, @text) = @_;
96  
97 4 my $meth = $self->{_markup_method};
98 4 $self->{_instance}->$meth(@text);
99 }
100  
101 1 ▶sub markupper {
Subroutine markupper: called CC=2 SCAR=7.1
Pod undocumented
102 1 my $class = shift;
103 1 ▶ $class = "Text::$class" unless $class =~ /^\+/;
Branch: 1 branch
BranchTrueFalseTotal
unless $class =~ /^\+/ 1 0 1
104  
105 1 __PACKAGE__->new($class, @_);
106 }
107  
108  
109 3 1;
110 __END__
↑ Summary