Wiki/Function.pm

filter: Statementstmt 100% 65 / 65 Branchbran 100% 8 / 8 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 17 / 17 Podpod 100% 8 / 8 totaltotal 100% 101 / 101 CC 7 SCAR 4.8
CC
7
Cov
100%
_load
3.0
has_function
2.0
get_args
2.0
CRAP 1.6
« Wiki/Plugin/Function/Youtube.pm ↑ Summary Wiki/Plugin/Block/Line.pm »
1 package Text::Livedoor::Wiki::Function;
2  
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use Text::Livedoor::Wiki::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 16 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
10 16 my $class = shift;
11 16 my $self = shift;
12 16 $self = bless $self, $class;
13 16 return $self;
14 }
15  
16 16 ▶sub setup {
Subroutine setup: called CC=1 SCAR=0.0
Pod documented
17 16 my $self = shift;
18 16 my $inline = shift;
19 16 my $plugins = delete $self->{plugins};
20 16 $self->{inline} = $inline ;
21 16 Scalar::Util::weaken($self->{inline});
22 16 $self->_load( $plugins );
23 15 return 1;
24 }
25 126 ▶sub inline {
Subroutine inline: called CC=1 SCAR=0.0
Pod documented
26 126 my $self = shift;
27 126 return $self->{inline};
28 }
29 152 ▶sub has_function {
Subroutine has_function: called CC=2 SCAR=6.9
Pod documented
30 152 my $self = shift;
31 152 my $function_name = shift;
32 152 ▶ return $self->{function}{ $function_name } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'function'}{$function_name} ? : 151 1 152
33 }
34 151 ▶sub get_args {
Subroutine get_args: called CC=2 SCAR=6.9
Pod documented
35 151 my $self = shift;
36 151 ▶ my $opr = shift || '';
Condition100%2/2
shift() || ''
l!l
13318
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
37 151 $opr =~ s/\s//g;
38 151 my @args = split(',',$opr );
39 151 return \@args;
40 }
41 151 ▶sub prepare {
Subroutine prepare: called CC=2 SCAR=6.9
Pod documented
42 151 my $self = shift;
43 151 my $function_name = shift;
44 151 my $opr = shift;
45 151 my $tail_part = shift;
46 151 my $args = $self->get_args( $opr );
47 151 my $res = {};
48 151 eval {
49 151 my $my_args = $self->{function}->{$function_name}{prepare_args}->( $args );
50 126 my $value = $self->{function}->{$function_name}{prepare_value}->( $tail_part );
51 126 $res = { args => $my_args , value => $value };
52 };
53 151 ▶ if ($@ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 25 126 151
54 #warn $@;
55 25 return;
56 }
57  
58 126 return $res;
59 }
60  
61 126 ▶sub parse {
Subroutine parse: called CC=1 SCAR=0.0
Pod documented
62 126 my $self = shift;
63 126 my $function_name = shift;
64 126 $self->{function}->{$function_name}{process}->(@_);
65 }
66  
67 126 ▶sub on_mobile { shift->{on_mobile} }
Subroutine on_mobile: called CC=1 SCAR=0.0
Pod documented
68  
69 16 ▶sub _load {
Subroutine _load: called CC=3 SCAR=11.0
70 16 my $self = shift;
71 16 my $plugins = shift;
72 16 my %function = ();
73 16 for my $plugin (@$plugins) {
74 159 ▶ $plugin->require or die $@;
Branch: 1 branch
BranchTrueFalseTotal
$plugin->require or die $@ 158 1 159
75 $function{$plugin->function_name} = {
76 operation_regexp => $plugin->operation_regexp,
77 126 ▶ process => sub { $self->on_mobile ? $plugin->process_mobile( $self->inline , @_) : $plugin->process( $self->inline , @_) } ,
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->on_mobile ? : 17 109 126
78 151 ▶ prepare_args => sub { $plugin->prepare_args(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
79 126 ▶ prepare_value => sub { $plugin->prepare_value(@_) }
Subroutine __ANON__: called CC=1 SCAR=0.0
80 }
81 158 }
82 15 $self->{function} = \%function;
83  
84 15 1;
85 }
86  
87 13 1;
88  
89 =head1 NAME
90  
91 Text::Livedoor::Wiki::Function - Wiki Function Parser Class
92  
93 =head1 DESCRIPTION
94  
95 Function Parser
96  
97 =head1 METHOD
98  
99 =head2 get_args
100  
101 =head2 has_function
102  
103 =head2 inline
104  
105 =head2 new
106  
107 =head2 on_mobile
108  
109 =head2 parse
110  
111 =head2 prepare
112  
113 =head2 setup
114  
115 =head1 AUTHOR
116  
117 polocky
118  
119 =cut
« Wiki/Plugin/Function/Youtube.pm ↑ Summary Wiki/Plugin/Block/Line.pm »