PML/Alt.pm

filter: Statementstmt 26.4% 14 / 53 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 35.7% 5 / 14 Podpod 100% 9 / 9 totaltotal 31.8% 28 / 88 CC 7 SCAR 17.1
CC
7
Cov
22%
new_from_ref
12.0
add_list
12.0
delete_value
6.0
CRAP 5.5
« PML/Instance/Common.pm ↑ Summary PML/Schema/Member.pm »
1  
2 package Treex::PML::Alt;
3 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 $VERSION='2.29'; # version template
9 }
10 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 Treex::PML::Alt - an alternative of uniformly typed PML values
15  
16 =head1 DESCRIPTION
17  
18 This class implements the attribute value type 'alternative'.
19  
20 =over 4
21  
22 =cut
23  
24  
25 =item Treex::PML::Alt->new (value1,value2,...)
26  
27 Create a new alternative (optionally populated with given values).
28  
29 NOTE: Don't call this constructor directly, use Treex::PML::Factory->createAlt() instead!
30  
31 =cut
32  
33 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
34 0 my $class = shift;
35 0 return bless [@_],$class;
36 }
37  
38  
39 =item Treex::PML::Alt->new_from_ref (array_ref, reuse)
40  
41 Create a new alternative consisting of values in a given array
42 reference. If reuse is true, then the same array_ref scalar is reused
43 to represent the Treex::PML::Alt object (i.e. blessed). Otherwise, a copy is
44 created in the constructor.
45  
46 NOTE: Don't call this constructor directly, use Treex::PML::Factory->createAlt() instead!
47  
48 =cut
49  
50 0 ▶sub new_from_ref {
Subroutine new_from_ref: not called CC=3 SCAR=24.8
Pod documented
51 0 my ($class,$array,$reuse) = @_;
52 0 ▶ if ($reuse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reuse) { } 0 0 0
53 0 ▶ if (UNIVERSAL::isa($array,'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($array, 'ARRAY')) { } 0 0 0
54 0 return bless $array,$class;
55 } else {
56 0 croak("Usage: new_from_ref(ARRAY_REF,1) - arg 1 is not an ARRAY reference!");
57 }
58 } else {
59 0 return bless [@$array],$class;
60 }
61 }
62  
63  
64 =item $alt->values ()
65  
66 Retrurns a its values (i.e. the alternatives).
67  
68 =cut
69  
70 0 ▶sub values {
Subroutine values: not called CC=1 SCAR=6.9
Pod documented
71 0 return @{$_[0]};
72 }
73  
74 =item $alt->count ()
75  
76 Retrurn number of values in the alternative.
77  
78 =cut
79  
80 0 ▶sub count {
Subroutine count: not called CC=1 SCAR=6.9
Pod documented
81 0 return scalar(@{$_[0]});
82 }
83  
84 =item $alt->add (@values)
85  
86 Add given values to the alternative. Only values which are not already
87 included in the alternative are added.
88  
89 =cut
90  
91 0 ▶sub add {
Subroutine add: not called CC=1 SCAR=6.9
Pod documented
92 0 my $self = shift;
93 0 $self->add_list(\@_);
94 0 return $self;
95 }
96  
97 =item $alt->add_list ($list)
98  
99 Add values of the given list to the alternative. Only values which are
100 not already included in the alternative are added.
101  
102 =cut
103  
104 0 ▶sub add_list {
Subroutine add_list: not called CC=3 SCAR=24.8
Pod documented
105 0 ▶ die 'Usage: Treex::PML::Alt->add_list() (wrong number of arguments!)'
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 0 0
106 if @_!=2;
107 0 my $self = shift;
108 0 my $list = shift;
109 0 my %a; @a{ @$self } = ();
110 0 ▶ push @{$self}, grep { exists($a{$_}) ? 0 : ($a{$_}=1) } @$list;
Branch: 1 branch
BranchTrueFalseTotal
exists $a{$_} ? : 0 0 0
111 0 return $self;
112 }
113  
114 =item $alt->delete_value ($value)
115  
116 Delete all occurences of value $value. Values are compared as strings.
117  
118 =cut
119  
120 0 ▶sub delete_value {
Subroutine delete_value: not called CC=2 SCAR=17.9
Pod documented
121 0 ▶ die 'Usage: Treex::PML::Alt->delete_value($value) (wrong number of arguments!)'
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 0 0
122 if @_!=2;
123 0 my ($self,$value) = @_;
124 0 @$self = grep { $_ ne $value } @$self;
125 0 return $self;
126 }
127  
128 =item $alt->delete_values ($value1,$value2,...)
129  
130 Delete all occurences of values $value1, $value2,... Values are
131 compared as strings.
132  
133 =cut
134  
135 0 ▶sub delete_values {
Subroutine delete_values: not called CC=1 SCAR=6.9
Pod documented
136 0 my $self = shift;
137 0 my %d; %d = @_;
138 0 @$self = grep { !exists($d{$_}) } @$self;
139 0 return $self;
140 }
141  
142 =item $list->empty ()
143  
144 Remove all values from the alternative.
145  
146 =cut
147  
148 0 ▶sub empty {
Subroutine empty: not called CC=2 SCAR=17.9
Pod documented
149 0 ▶ die 'Usage: Treex::PML::Alt->empty() (wrong number of arguments!)'
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 1 0 0 0
150 if @_!=1;
151 0 my $self = shift;
152 0 @$self=();
153 0 return $self;
154 }
155  
156 =back
157  
158 =head1 SEE ALSO
159  
160 L<Treex::PML>, L<Treex::PML::Factory>, L<Treex::PML::Schema>, L<Treex::PML::List>
161  
162 =head1 COPYRIGHT AND LICENSE
163  
164 Copyright (C) 2006-2010 by Petr Pajas, 2010-2024 Jan Stepanek
165  
166 This library is free software; you can redistribute it and/or modify
167 it under the same terms as Perl itself, either Perl version 5.8.2 or,
168 at your option, any later version of Perl 5 you may have available.
169  
170 =cut
171  
172  
173 9 1;
« PML/Instance/Common.pm ↑ Summary PML/Schema/Member.pm »