Wiki/Inline.pm

filter: Statementstmt 100% 75 / 75 Branchbran 100% 14 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 100% 111 / 111 CC 12 SCAR 11.8
CC
12
Cov
100%
parse
6.0
_sort
5.0
_load
2.0
CRAP 3.2
« Wiki.pm ↑ Summary Wiki/Plugin/Function/Fukidashi.pm »
1 package Text::Livedoor::Wiki::Inline;
2  
3 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Text::Livedoor::Wiki::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 16 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
9 16 my $class = shift;
10 16 my $self = shift;
11 16 $self = bless $self, $class;
12 16 my $plugins = delete $self->{plugins};
13 16 $self->_load( $plugins );
14 15 $self->function->setup( $self );
15 15 return $self;
16 }
17  
18 444 ▶sub function { shift->{function} }
Subroutine function: called CC=1 SCAR=0.0
Pod documented
19 493 ▶sub _build_catchall {
Subroutine _build_catchall: called CC=1 SCAR=0.0
20 493 my $self = shift;
21  
22 my $regex
23 493 = join( '|', map { '(' . $_->{regex} . ')' } @{ $self->{elements} } );
24 493 return q{((?:.|^|$)+?(?=} . $regex . q{|$))};
25 }
26  
27 432 ▶sub _no_match {
Subroutine _no_match: called CC=1 SCAR=0.0
28 432 my ( $self, $char ) = @_;
29 432 return Text::Livedoor::Wiki::Utils::escape($char);
30 }
31  
32 538 ▶sub parse {
Subroutine parse: called CC=6 SCAR=17.9
Pod documented
33 538 my $self = shift;
34 538 my $line = shift;
35 538 ▶ return '' unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 3 535 538
36  
37 535 chomp($line);
38  
39 535 ▶ return '' if ( $line eq '' );
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "" 42 493 535
40  
41 493 my $catchall = {
42 regex => $self->_build_catchall,
43 n_args => 1,
44 process => \&_no_match,
45 };
46  
47 493 my $formatted = '';
48  
49 493 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
pos $line < length $line and do { do { foreach my $element (@{$$self{"elements"};}, $catchall) { if ($line =~ /\G($element->{"regex"})/cgis) { ++$Text::Livedoor::Wiki::scratchpad->{"core"}{"inline_uid"}; my $arg_idx = 0; my $matched = eval '$' . ++$arg_idx; my(@args) = map({eval '$' . ++$arg_idx;} 1 .. $element->{"n_args"}); $formatted .= &{$element->{"process"};}($self, @args); last; } ; } } } 146 493 639
50 639 for my $element ( @{$self->{elements}}, $catchall ) {
51 6673 ▶ if ( $line =~ m/\G($element->{regex})/gcis ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\G($element->{"regex"})/cgis) 639 6034 6673
52 639 $Text::Livedoor::Wiki::scratchpad->{core}{inline_uid}++;
53 639 my $arg_idx = 0;
54 639 my $matched = eval( q{$} . ( ++$arg_idx ) );
55 639 my @args = map { eval( q{$} . ( ++$arg_idx ) ) } ( 1 .. $element->{n_args} );
56 639 $formatted .= &{$element->{process}}( $self, @args );
57 639 last;
58 }
59 }
60 } while ( pos($line) < length($line) );
61  
62 493 return $formatted;
63  
64 }
65  
66 207 ▶sub on_mobile { shift->{on_mobile} }
Subroutine on_mobile: called CC=1 SCAR=0.0
Pod documented
67  
68 16 ▶sub _load {
Subroutine _load: called CC=2 SCAR=6.9
69 16 my $self = shift;
70 16 my $plugins = shift;
71 16 $plugins = $self->_sort( $plugins );
72 15 my @elements = ();
73 15 for my $plugin (@$plugins) {
74 my $element = {
75 regex => $plugin->regex,
76 n_args => $plugin->n_args,
77 207 ▶ process => sub { $self->on_mobile ? $plugin->process_mobile(@_) : $plugin->process(@_) } ,
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->on_mobile ? : 20 187 207
78 139 };
79 139 push @elements , $element;
80 }
81 15 $self->{elements} = \@elements;
82  
83 15 1;
84 }
85  
86 # XXX this sort function is idiot but it's work for now :-p
87 16 ▶sub _sort {
Subroutine _sort: called CC=5 SCAR=16.1
88 16 my $self = shift;
89 16 my $plugins = shift;
90 16 @$plugins = sort @$plugins;
91 16 my @sorted_plugins = ();
92 16 my %remember_me = ();
93 16 my @stacks = ();
94 16 for ( @$plugins ) {
95 140 ▶ $_->require() or die $@;
Branch: 1 branch
BranchTrueFalseTotal
$_->require or die $@ 139 1 140
96 139 $remember_me{ $_ } = 1;
97 139 my $dependency = $_->dependency ;
98 139 ▶ if ( $dependency && !$remember_me{ $dependency } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dependency and not $remember_me{$dependency}) 34 105 139
Condition100%3/3
$dependency and not $remember_me{$dependency}
!ll&&!rl&&r
103234
MC/DC100%2/2
$dependency and not $remember_me{$dependency}
$dependency not $remember_me{$dependency}
Truth table100%3/3
A and not(B)
A= $dependencyB= not $remember_me{$dependency}
ABresult
0X0
100
111
99 34 push @stacks , $_;
100 34 next;
101 }
102 105 push @sorted_plugins , $_;
103 }
104 15 push @sorted_plugins , @stacks;
105 15 return \@sorted_plugins;
106 }
107 12 1;
108  
109 =head1 NAME
110  
111 Text::Livedoor::Wiki::Inline - Wiki Inline Parser
112  
113 =head1 DESCRIPTION
114  
115 inline parser
116  
117 =head1 METHOD
118  
119 =head2 function
120  
121 =head2 new
122  
123 =head2 on_mobile
124  
125 =head2 parse
126  
127 =head1 AUTHOR
128  
129 polocky
130  
131 =cut
« Wiki.pm ↑ Summary Wiki/Plugin/Function/Fukidashi.pm »