Sense.pm

filter: Statementstmt 72.6% 53 / 73 Branchbran 40.9% 9 / 22 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 76.4% 13 / 17 Podpod 11.1% 1 / 9 totaltotal 63.5% 82 / 129 SCAR 33.4
CC
17
Cov
66%
parser
7.1
serialiser
7.1
AUTOLOAD
6.9
CRAP 28.4
« Parse/Simple.pm ↑ Summary Pronounce/Pronouncer.pm »
1 package WordLists::Sense;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 our $AUTOLOAD;
6 5 ▶use WordLists::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 our $VERSION = $WordLists::Base::VERSION;
8
9 =head1 NAME
10
11 WordLists::Sense - Class for senses in wordlists, dictionaries, etc.
12
13 =head1 SYNOPSIS
14
15 use WordLists::Sense;
16 my $sense = WordLists::Sense->new();
17 $sense->set('hw', 'head');
18 $sense->set('pos', 'noun');
19 $sense->set_pos('verb'); # alternative
20 $sense->has('pos'); # returns 1
21 $sense->get('pos'); # returns 'verb'
22 $sense->to_string; # returns "head\tverb" - however it is better to do this from within a wordlist
23 my $another_sense = WordLists::Sense->new({hw=>'head', pos=>'verb'});
24
25 This class is a very simple class which is little more than a blessed hash with accessors C<set>, C<get>, and C<has>.
26
27 The following attributes are 'special' - treated no differently by this module but by others:
28
29 =over
30
31 =item *
32 C<hw> - ('headword') - all searches will be keyed to this
33
34 =item *
35 C<pos> - ('part of speech') - this is a discriminator for finer control
36
37 =item *
38 C<dict> - ('dictionary') - this is set by a L<WordLists::Dict> object when the sense is added to that object to assert provenance
39
40 =back
41
42 =head1 BUGS
43
44 Please use the Github issues tracker.
45
46 =head1 LICENSE
47
48 Copyright 2011-2012 © Cambridge University Press. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
49
50 =cut
51
52 sub new
53 {
54 24 ▶ my ($class, $args) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
55 24 my $self = $args;
56 24 ▶ $self ||={};
Condition100%2/2
$self ||= {}
l!l
1410
MC/DC100%1/1
$self ||= {}
$self
Truth table100%2/2
A
A= $self
Aresult
11
00
57 24 bless ($self, $class);
58 24 return $self;
59 }
60
61 sub get
62 {
63 18 ▶ my ($self, $attr) = @_;
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
64 18 return $self->{$attr};
65 }
66 sub parser
67 {
68 0 ▶ my ($self, $parser) = @_;
Subroutine parser: not called CC=3 SCAR=19.6
Pod undocumented
69 0 ▶ if (defined $parser)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parser) 0 0 0
70 {
71 0 $self->{'#parser'} = $parser;
72 }
73 0 ▶ if (defined $self->{'#parser'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'#parser'}) { } 0 0 0
74 {
75 0 return $self->{'#parser'}
76 }
77 else
78 {
79 5 ▶ use WordLists::Parse::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 0 $self->{'#parser'} = WordLists::Parse::Simple->new();
81 }
82 }
83 sub serialiser
84 {
85 0 ▶ my ($self, $serialiser) = @_;
Subroutine serialiser: not called CC=3 SCAR=19.6
Pod undocumented
86 0 ▶ if (defined $serialiser)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $serialiser) 0 0 0
87 {
88 0 $self->{'#serialiser'} = $serialiser;
89 }
90 0 ▶ if (defined $self->{'#serialiser'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'#serialiser'}) { } 0 0 0
91 {
92 0 return $self->{'#serialiser'}
93 }
94 else
95 {
96 5 ▶ use WordLists::Serialise::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 0 $self->{'#serialiser'} = WordLists::Serialise::Simple->new();
98 }
99 }
100
101
102 sub set
103 {
104 1 ▶ my ($self, $attr, $value) = @_;
Subroutine set: called CC=1 SCAR=0.0
Pod documented
105 1 return $self->{$attr} = $value;
106 }
107 sub has
108 {
109 0 ▶ my ($self, $attr) = @_;
Subroutine has: not called CC=1 SCAR=6.9
Pod undocumented
110 0 return defined $self->{$attr};
111 }
112 sub read_hash
113 {
114 0 ▶ my ($self, $hash, $args) = @_;
Subroutine read_hash: not called CC=2 SCAR=17.9
Pod undocumented
115 0 foreach (keys %{$hash})
116 {
117 0 $self->set($_, $hash->{$_});
118 }
119 0 return $self;
120 }
121 sub to_hash
122 {
123 2 ▶ my ($self, $args) = @_;
Subroutine to_hash: called CC=4 SCAR=13.9
Pod undocumented
124 2 my $hash = {};
125 2 ▶ unless (defined $args->{'fields'})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args->{"fields"}) 2 0 2
126 {
127 2 $args->{'fields'} = [];
128 2 push (@{$args->{'fields'}} , $_) foreach keys %{ $self } ;
129 }
130 2 $hash->{$_} = $self->get($_) foreach @{$args->{'fields'}};
131 2 return $hash;
132 }
133 sub to_string # should we ditch this?
134 {
135 1 ▶ my ($self, $args) = @_;
Subroutine to_string: called CC=2 SCAR=6.9
Pod undocumented
136 my $opts = {
137 field_prefix => "",
138 field_suffix => "",
139 sense_prefix => "",
140 sense_suffix => "",
141 separator => "\t",
142 fields => [qw(hw pos def eg)],
143 4 ▶ field_escape => sub { return defined $_[0] ? $_[0] : ''; },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 2 2 4
144 1 ▶ defined $args ? %$args : (),
Branch: 1 branch
BranchTrueFalseTotal
defined $args ? : 0 1 1
145 };
146
147 my $s =
148 $opts->{'sense_prefix'} .
149 join ($opts->{'separator'}, map {
150 $opts->{'field_prefix'} .
151 4 &{$opts->{'field_escape'}}($self->get($_), $_) .
152 4 $opts->{'field_suffix'}
153 1 } @{$opts->{'fields'}})
154 1 . $opts->{'sense_suffix'}
155 ;
156 1 return $s;
157 }
158
159 sub AUTOLOAD
160 {
161 124 ▶ my $self = shift;
Subroutine AUTOLOAD: called CC=6 SCAR=19.3
162 124 ▶ return if ($AUTOLOAD =~ /DESTROY/);
Branch: 1 branch
BranchTrueFalseTotal
if $WordLists::Sense::AUTOLOAD =~ /DESTROY/ 24 100 124
163 100 ▶ if ( ($AUTOLOAD =~ /.*::set_(\w+)/) and (@_) )
Branch: 3 branches
BranchTrueFalseTotal
if ($WordLists::Sense::AUTOLOAD =~ /.*::set_(\w+)/ and @_) { } 37 63 100
elsif ($WordLists::Sense::AUTOLOAD =~ /.*::get_(\w+)/) { } 63 0 63
elsif ($WordLists::Sense::AUTOLOAD =~ /.*::has_(\w+)/) { } 0 0 0
Condition66%2/3
$WordLists::Sense::AUTOLOAD =~ /.*::set_(\w+)/ and @_
!ll&&!rl&&r
63037
MC/DC50%1/2
$WordLists::Sense::AUTOLOAD =~ /.*::set_(\w+)/ and @_
$WordLists::Sense::AUTOLOAD =~ /.*::set_(\w+)/ @_
Truth table66%2/3
A and B
A= $WordLists::Sense::AUTOLOAD =~ /.*::set_(\w+)/B= @_
ABresult
0X0
100
111
164 {
165 37 return $self->{$1} = shift;
166 }
167 elsif ($AUTOLOAD =~ /.*::get_(\w+)/)
168 {
169 63 return $self->{$1};
170 }
171 elsif ($AUTOLOAD =~ /.*::has_(\w+)/)
172 {
173 0 return defined $self->{$1};
174 }
175 }
176
177
178 5 1;
« Parse/Simple.pm ↑ Summary Pronounce/Pronouncer.pm »