Parser/TemplateParser.pm

filter: Statementstmt 42.8% 24 / 56 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 9 totaltotal 36.1% 30 / 83 CC 5 SCAR 15.0
CC
5
Cov
39%
parse_template
12.0
template_ws_sense
6.0
template_ws
6.0
CRAP 4.5
« Parser/Section.pm ↑ Summary Parser/Language.pm »
1 package Wiktionary::Parser::TemplateParser;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 81 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
8 81 my $class = shift;
9 81 my %args = @_;
10 81 my $self = bless \%args, $class;
11 81 return $self;
12 }
13  
14 # given a line of text, extract the content of each template
15 52 ▶sub extract_templates {
Subroutine extract_templates: called CC=1 SCAR=0.0
Pod undocumented
16 52 my $self = shift;
17 52 my %args = @_;
18 52 my $line = $args{line};
19  
20 52 my @templates = $line =~ m/\{\{([^\}]+)\}\}/g;
21  
22 52 return @templates;
23 }
24  
25 52 ▶sub extract_tokens {
Subroutine extract_tokens: called CC=1 SCAR=0.0
Pod undocumented
26 52 my $self = shift;
27 52 my %args = @_;
28 52 my $line = $args{line};
29  
30 52 my @tokens = $line =~ m/\[\[([^\]]+)\]\]/g;
31  
32 52 return @tokens;
33 }
34  
35  
36 0 ▶sub parse_template {
Subroutine parse_template: not called CC=3 SCAR=24.8
Pod undocumented
37 0 my $self = shift;
38 0 my %args = @_;
39 0 my $template = $args{template};
40  
41 0 my @parts = split(/\|/,$template);
42  
43 0 my $template_type = shift @parts;
44 0 $template_type =~ s/\s+/_/g;
45 0 my $template_parsing_method = "template_$template_type";
46  
47 0 my $meta = {};
48 0 ▶ if ($self->can($template_parsing_method)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->can($template_parsing_method)) { } 0 0 0
elsif (@parts) { } 0 0 0
49 0 $meta = $self->$template_parsing_method(@parts);
50 } elsif (@parts) {
51 0 $meta = { content => \@parts };
52 }
53  
54 0 $meta->{template_type} = $template_type;
55  
56 0 return $meta;
57 }
58  
59 0 ▶sub template_ws_beginlist {
Subroutine template_ws_beginlist: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my $self = shift;
61 0 return {meta => 'begin'};
62 }
63  
64 0 ▶sub template_ws_endlist {
Subroutine template_ws_endlist: not called CC=1 SCAR=6.9
Pod undocumented
65 0 my $self = shift;
66 0 return {meta => 'end'};
67 }
68  
69  
70 0 ▶sub template_ws_sense {
Subroutine template_ws_sense: not called CC=2 SCAR=17.9
Pod undocumented
71 0 my ($self, @parts) = @_;
72 0 my %meta;
73 0 for my $part (@parts) {
74 0 push @{$meta{sense}}, $part;
75 }
76 0 return \%meta;
77 }
78  
79 0 ▶sub template_ws {
Subroutine template_ws: not called CC=2 SCAR=17.9
Pod undocumented
80 0 my ($self, @parts) = @_;
81 0 my %meta;
82 0 $meta{word} = $parts[0];
83 0 ▶ $meta{gloss} = $parts[-1] if scalar @parts > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @parts > 1 0 0 0
84 0 return \%meta;
85 }
86  
87 0 ▶sub template_l {
Subroutine template_l: not called CC=1 SCAR=6.9
Pod undocumented
88 0 my ($self, @parts) = @_;
89 0 my %meta;
90 0 $meta{lang} = $parts[0];
91 0 $meta{word} = $parts[1];
92 }
93  
94  
95 3 1;
« Parser/Section.pm ↑ Summary Parser/Language.pm »