PML/Struct.pm

filter: Statementstmt 65.7% 23 / 35 Branchbran 20.0% 2 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 8 / 12 Podpod 100% 5 / 5 totaltotal 61.2% 38 / 62 CC 6 SCAR 11.8
CC
6
Cov
56%
get_member
6.0
set_member
6.0
delete_member
6.0
CRAP 3.3
« PML/Seq.pm ↑ Summary PML/Factory.pm »
1  
2 =head1 NAME
3  
4 Treex::PML::Struct - PML attribute value structure
5  
6 =head1 DESCRIPTION
7  
8 This class implements the data type 'structure'. Structure consists
9 of items called members. Each member is a name-value pair, where the
10 name uniquely determines the member within the structure
11 (i.e. distinct members of a structure have distinct names).
12  
13 =over 4
14  
15 =cut
16  
17 package Treex::PML::Struct;
18 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 9 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
23 9 $VERSION='2.29'; # version template
24 }
25 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 9 ▶use UNIVERSAL::DOES;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 =item Treex::PML::Struct->new ({name=>value, ...},reuse?)
29  
30 NOTE: Don't call this constructor directly, use Treex::PML::Factory->createStructure() instead!
31  
32 Create a new structure (optionally initializing its members). If
33 reuse is true, the hash reference passed may be reused (re-blessed)
34 into the structure.
35  
36 =cut
37  
38 15493 ▶sub new {
Subroutine new: called CC=3 SCAR=12.5
Pod documented
39 15493 my ($class,$hash,$reuse) = @_;
40 15493 ▶ if (ref $hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash) { } 15493 0 15493
41 15493 ▶ return $reuse ? bless $hash, $class
Branch: 1 branch
BranchTrueFalseTotal
$reuse ? : 15493 0 15493
42 : bless Treex::PML::CloneValue($hash), $class;
43 } else {
44 0 return bless {}, $class;
45 }
46 }
47  
48 =item $struct->get_member ($name)
49  
50 Return value of the given member.
51  
52 =cut
53  
54 0 ▶sub get_member {
Subroutine get_member: not called CC=2 SCAR=17.9
Pod documented
55 0 my ($self,$name) = @_;
56 0 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
57 0 return $self->{$name};
58 }
59  
60 =item $struct->set_member ($name,$value)
61  
62 Set value of the given member.
63  
64 =cut
65  
66 0 ▶sub set_member {
Subroutine set_member: not called CC=2 SCAR=17.9
Pod documented
67 0 my ($self,$name,$value) = @_;
68 0 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
69 0 return $self->{$name}=$value;
70 }
71  
72  
73 =item $struct->delete_member ($name)
74  
75 Delete the given member (returning its last value).
76  
77 =cut
78  
79 0 ▶sub delete_member {
Subroutine delete_member: not called CC=2 SCAR=17.9
Pod documented
80 0 my ($self,$name) = @_;
81 0 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
82 0 return delete $self->{$name};
83 }
84  
85 =item $struct->members ()
86  
87 Return (assorted) list of names of all members.
88  
89 =cut
90  
91 0 ▶sub members {
Subroutine members: not called CC=1 SCAR=6.9
Pod documented
92 0 return keys %{$_[0]};
93 }
94  
95  
96 =back
97  
98 =cut
99  
100 15691 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
101 15691 my ($self) = @_;
102 15691 %{$self}=(); # this should not be needed, but
103 # without it, perl 5.10 leaks on weakened
104 # structures, try:
105 # Scalar::Util::weaken({}) while 1
106 }
107  
108 9 1;
109 __END__
« PML/Seq.pm ↑ Summary PML/Factory.pm »