File Coverage

blib/lib/Wiktionary/Parser/Section/PartofSpeech.pm
Criterion Covered Total %
statement 34 40 85.0
branch 8 8 100.0
condition n/a
subroutine 7 10 70.0
pod 0 8 0.0
total 49 66 74.2


line stmt bran cond sub pod time code
1             package Wiktionary::Parser::Section::PartofSpeech;
2              
3 3     3   22 use Wiktionary::Parser::Section;
  3         7  
  3         94  
4              
5 3     3   17 use base qw(Wiktionary::Parser::Section);
  3         7  
  3         2155  
6              
7             sub new {
8 12     12 0 99 my $class = shift;
9 12         69 my %args = @_;
10 12         74 my $self = bless Wiktionary::Parser::Section->new(%args), $class;
11              
12             # in some poorly formatted sections,
13             # we can still get the part of speech and language from section headers
14             # if they are not defined in markup
15 12         54 $self->set_part_of_speech($self->get_header());
16 12         44 $self->set_language_code($self->get_language());
17 12         49 return $self;
18             }
19              
20             # add a line of content to this section and parse it into its component parts
21             sub add_content {
22 58     58 0 74 my $self = shift;
23 58         69 my $line = shift;
24            
25 58 100       163 if ($line =~ m/^\{\{([^\}]+)\}\}/) {
26 11         25 my $header_meta = $1;
27 11         38 my @meta_parts = split(/\|/,$header_meta);
28            
29             # e.g. {{head|en|noun}}
30 11 100       74 if ($meta_parts[0] eq 'head') {
    100          
    100          
31 2         7 $self->set_language_code($meta_parts[1]);
32 2         7 $self->set_part_of_speech($meta_parts[2])
33              
34              
35             } elsif ($meta_parts[0] =~ m/^(\w+)\-(\w+)-(\w+)\|?/) {
36             # {{roa-jer-noun|...
37 2         7 $self->set_language_code($1);
38 2         6 $self->set_part_of_speech($3);
39 2         9 $self->set_inflection([@meta_parts[1..-1]]);
40              
41             } elsif ($meta_parts[0] =~ m/^(\w+)\-(\w+)/) {
42             # e.g. {{en-noun|...}}
43 6         38 $self->set_language_code($1);
44 6         12 $self->set_part_of_speech($2);
45 6         22 $self->set_inflection([@meta_parts[1..-1]]);
46             }
47             }
48            
49 58         62 push @{$self->{content}}, $line;
  58         254  
50             }
51              
52             sub set_part_of_speech {
53 22     22 0 28 my $self = shift;
54 22         54 $self->{part_of_speech} = shift;
55             }
56              
57             sub get_part_of_speech {
58 0     0 0 0 my $self = shift;
59 0         0 return $self->{part_of_speech};
60             }
61              
62              
63             sub set_language_code {
64 22     22 0 33 my $self = shift;
65 22         53 $self->{language_code} = shift;
66             }
67              
68             sub get_language_code {
69 0     0 0 0 my $self = shift;
70 0         0 return $self->{language_code};
71             }
72              
73             sub set_inflection {
74 8     8 0 10 my $self = shift;
75 8         24 $self->{inflection} = shift;
76             }
77              
78             sub get_inflection {
79 0     0 0   my $self = shift;
80 0           return $self->{inflection};
81             }
82              
83              
84              
85             1;