File Coverage

blib/lib/Treex/PML/Struct.pm
Criterion Covered Total %
statement 22 34 64.7
branch 2 10 20.0
condition n/a
subroutine 8 12 66.6
pod 5 5 100.0
total 37 61 60.6


line stmt bran cond sub pod time code
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 6     6   47 use Carp;
  6         11  
  6         291  
19 6     6   31 use warnings;
  6         10  
  6         145  
20              
21 6     6   36 use vars qw($VERSION);
  6         10  
  6         263  
22             BEGIN {
23 6     6   119 $VERSION='2.24'; # version template
24             }
25 6     6   38 use strict;
  6         12  
  6         118  
26 6     6   28 use UNIVERSAL::DOES;
  6         20  
  6         1635  
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             sub new {
39 15488     15488 1 27159 my ($class,$hash,$reuse) = @_;
40 15488 50       27898 if (ref $hash) {
41 15488 50       40862 return $reuse ? bless $hash, $class
42             : bless Treex::PML::CloneValue($hash), $class;
43             } else {
44 0         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             sub get_member {
55 0     0 1 0 my ($self,$name) = @_;
56 0 0       0 return unless defined $name;
57 0         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             sub set_member {
67 0     0 1 0 my ($self,$name,$value) = @_;
68 0 0       0 return unless defined $name;
69 0         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             sub delete_member {
80 0     0 1 0 my ($self,$name) = @_;
81 0 0       0 return unless defined $name;
82 0         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             sub members {
92 0     0 1 0 return keys %{$_[0]};
  0         0  
93             }
94              
95              
96             =back
97              
98             =cut
99              
100             sub DESTROY {
101 15689     15689   60197 my ($self) = @_;
102 15689         17888 %{$self}=(); # this should not be needed, but
  15689         72259  
103             # without it, perl 5.10 leaks on weakened
104             # structures, try:
105             # Scalar::Util::weaken({}) while 1
106             }
107              
108             1;
109             __END__