lib/Text/Xatena/Node/Blockquote.pm

filter: Statementstmt 100% 31 / 31 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 93.8% 46 / 49 CC 6 SCAR 11.0
CC
6
Cov
98%
parse
5.0
as_html
2.0
BEGIN
1.0
CRAP 3.0
« lib/Text/Xatena/Node/StopP.pm ↑ Summary blib/lib/Text/Xatena/Node.pm »
1 package Text::Xatena::Node::Blockquote;
2  
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 19 ▶use base qw(Text::Xatena::Node);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 19 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 BEGINNING => qr/^>(.*?)>$/,
8 ENDOFNODE => qr/^<<$/,
9 19 };
10  
11 391 ▶sub parse {
Subroutine parse: called CC=5 SCAR=16.1
Pod undocumented
12 391 my ($class, $s, $parent, $stack) = @_;
13 391 ▶ if ($s->scan(BEGINNING)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->scan(qr/^>(.*?)>$/)) 14 377 391
14 14 my $node = $class->new;
15 14 $node->{beginning} = $s->matched;
16 14 push @$parent, $node;
17 14 push @$stack, $node;
18 14 return 1;
19 }
20 377 ▶ if ($s->scan(ENDOFNODE)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->scan(qr/^<<$/)) 14 363 377
21 14 ▶ pop @$stack while ref($stack->[-1]) eq 'Text::Xatena::Node::Section';
Branch: 1 branch
BranchTrueFalseTotal
ref $stack->[-1] eq "Text::Xatena::Node::Section" and do { pop @$stack } 1 14 15
22 14 my $node = pop @$stack;
23 14 ▶ ref($node) eq $class or warn sprintf("syntax error: unmatched syntax got:%s expected:%s", ref($node), $class);
Branch: 1 branch
BranchTrueFalseTotal
ref $node eq $class or warn sprintf('syntax error: unmatched syntax got:%s expected:%s', ref $node, $class) 14 0 14
24 14 $node->{endofnode} = $s->matched;
25 14 return 1;
26 }
27 }
28  
29 10 ▶sub as_html {
Subroutine as_html: called CC=2 SCAR=6.9
Pod undocumented
30 10 my ($self, $context, %opts) = @_;
31  
32 10 my $text = $self->{beginning}->[1];
33  
34 10 ▶ my $title = ($text =~ /^http/) ?
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /^http/ ? : 3 7 10
35 $context->inline->format('[' . $text . ']'):
36 $context->inline->format($text);
37  
38 10 my ($uri) = ($title =~ m{(https?://[^\s"':]+)});
39  
40 10 $context->_tmpl(__PACKAGE__, q[
41 <blockquote {{if ($cite) { }}cite="{{= $cite }}"{{ } }}>
42 {{= $content }}
43 {{ if ($title) { }}
44 <cite>{{= $title }}</cite>
45 {{ } }}
46 </blockquote>
47 ], {
48 cite => $uri,
49 title => $title,
50 content => $self->SUPER::as_html($context, %opts),
51 });
52 }
53  
54 19 1;
55 __END__
« lib/Text/Xatena/Node/StopP.pm ↑ Summary blib/lib/Text/Xatena/Node.pm »