| 1 | package Text::Xatena::Inline; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 20 | ▶ | use Text::Xatena::Inline::Base -Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use HTML::Entities; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | sub footnotes { | ||||||||||||||||||||||||||
|
Subroutine
footnotes: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 11 | 1 | ▶ | $self->{footnotes} || []; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | match qr{\[\]([\s\S]*?)\[\]}i => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | my ($self, $unlink) = @_; | |||||||||||||||||||||||||||
| 16 | 2 | $unlink; | |||||||||||||||||||||||||||
| 17 | 20 | }; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | match qr{(\(\(\(.*?\)\)\))}i => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | my ($self, $unlink) = @_; | |||||||||||||||||||||||||||
| 21 | 1 | $unlink; | |||||||||||||||||||||||||||
| 22 | 20 | }; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | match qr{\)(\(\(.*?\)\))\(}i => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | my ($self, $unlink) = @_; | |||||||||||||||||||||||||||
| 26 | 1 | $unlink; | |||||||||||||||||||||||||||
| 27 | 20 | }; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 6 | ▶ | match qr{\(\((.+?)\)\)}i => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 30 | 6 | my ($self, $note) = @_; | |||||||||||||||||||||||||||
| 31 | 6 | ▶ | push @{ $self->{footnotes} ||= [] }, {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"footnotes"} ||= []
MC/DC100%1/1
$self->{"footnotes"} ||= []
$self->{"footnotes"}
Truth table100%2/2
A
A= $self->{"footnotes"}
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 6 | my $number = @{ $self->{footnotes} }; | |||||||||||||||||||||||||||
| 34 | 6 | my $title = $note; | |||||||||||||||||||||||||||
| 35 | 6 | $title =~ s/<[^>]+>//g; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 6 | my $footnote = $self->{footnotes}->[-1]; | |||||||||||||||||||||||||||
| 38 | 6 | $footnote->{number} = $number; | |||||||||||||||||||||||||||
| 39 | 6 | $footnote->{note} = $note; | |||||||||||||||||||||||||||
| 40 | 6 | $footnote->{title} = $title; | |||||||||||||||||||||||||||
| 41 | 6 | return sprintf('<a href="#fn%d" title="%s">*%d</a>', | |||||||||||||||||||||||||||
| 42 | $number, | ||||||||||||||||||||||||||||
| 43 | $title, | ||||||||||||||||||||||||||||
| 44 | $number | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | 20 | }; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | match qr{(<a[^>]+>[\s\S]*?</a>)}i => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 2 | my ($self, $anchor) = @_; | |||||||||||||||||||||||||||
| 50 | 2 | $anchor; | |||||||||||||||||||||||||||
| 51 | 20 | }; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | ▶ | match qr{<!--.*-->} => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 55 | 2 | '<!-- -->'; | |||||||||||||||||||||||||||
| 56 | 20 | }; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 16 | ▶ | match qr{(<[^>]+>)}i => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 16 | my ($self, $tag) = @_; | |||||||||||||||||||||||||||
| 60 | 16 | $tag; | |||||||||||||||||||||||||||
| 61 | 20 | }; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 16 | ▶ | match qr<\[((?:https?|ftp)://[^\s:]+(?::\d+)?[^\s:]+)(:(?:title(?:=([^[]+))?|barcode))?\]>i => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.5
| |||||||||||||||||||||||||||||
| 64 | 16 | my ($self, $uri, $opt, $title) = @_; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 16 | ▶ | if ($opt) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 10 | ▶ | if ($opt =~ /^:barcode$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 2 | return sprintf('<img src="http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=%s" title="%s"/>', | |||||||||||||||||||||||||||
| 69 | uri_escape($uri), | ||||||||||||||||||||||||||||
| 70 | $uri, | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 8 | ▶ | if ($opt =~ /^:title/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 8 | ▶ | if (!$title && $self->{aggressive}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $title and $self->{"aggressive"}
MC/DC50%1/2
not $title and $self->{"aggressive"}
not $title
$self->{"aggressive"}
Truth table66%2/3
not(A) and B
A= not $titleB= $self->{"aggressive"}
| |||||||||||||||||||||||||||||
| 75 | 6 | $title = $self->cache->get($uri); | |||||||||||||||||||||||||||
| 76 | 6 | ▶ | if (not defined $title) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 6 | eval { | |||||||||||||||||||||||||||
| 78 | 6 | $title = $self->title_of($uri); | |||||||||||||||||||||||||||
| 79 | 6 | $self->cache->set($uri, $title, "30 days"); | |||||||||||||||||||||||||||
| 80 | }; | ||||||||||||||||||||||||||||
| 81 | 6 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | warn $@; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 8 | ▶ | return sprintf('<a href="%s">%s</a>', | ||||||||||||||||||||||||||
|
Condition50%1/2
$title || ''
MC/DC0%0/1
$title || ''
$title
Truth table50%1/2
A
A= $title
| |||||||||||||||||||||||||||||
| 87 | $uri, | ||||||||||||||||||||||||||||
| 88 | encode_entities(decode_entities($title || '')) | ||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||
| 92 | 6 | return sprintf('<a href="%s">%s</a>', | |||||||||||||||||||||||||||
| 93 | $uri, | ||||||||||||||||||||||||||||
| 94 | $uri | ||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 20 | }; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 15 | ▶ | match qr<\[?((?:https?|ftp):(?!([^\s<>\]]+?):(?:barcode|title))([^\s<>\]]+))\]?>i => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 101 | 15 | my ($self, $uri) = @_; | |||||||||||||||||||||||||||
| 102 | 15 | sprintf('<a href="%s">%s</a>', | |||||||||||||||||||||||||||
| 103 | $uri, | ||||||||||||||||||||||||||||
| 104 | $uri | ||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||
| 106 | 20 | }; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2 | ▶ | match qr<\[?mailto:([^\s\@:?]+\@[^\s\@:?]+(\?[^\s]+)?)\]?>i => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 109 | 2 | my ($self, $uri) = @_; | |||||||||||||||||||||||||||
| 110 | 2 | sprintf('<a href="mailto:%s">%s</a>', | |||||||||||||||||||||||||||
| 111 | $uri, | ||||||||||||||||||||||||||||
| 112 | $uri | ||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||
| 114 | 20 | }; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 1 | ▶ | match qr<\[tex:([^\]]+)\]>i => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 117 | 1 | my ($self, $tex) = @_; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 1 | return sprintf('<img src="http://chart.apis.google.com/chart?cht=tx&chl=%s" alt="%s"/>', | |||||||||||||||||||||||||||
| 120 | uri_escape($tex), | ||||||||||||||||||||||||||||
| 121 | encode_entities($tex) | ||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||
| 123 | 20 | }; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 20 | 1; | |||||||||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||||||||||