| 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 | 1 |  |  | 1 |  | 5 | use Carp; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 42 |  | 
| 19 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 20 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 1 |  |  | 1 |  | 3 | use vars qw($VERSION); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 40 |  | 
| 22 |  |  |  |  |  |  | BEGIN { | 
| 23 | 1 |  |  | 1 |  | 11 | $VERSION='2.21'; # version template | 
| 24 |  |  |  |  |  |  | } | 
| 25 | 1 |  |  | 1 |  | 4 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 17 |  | 
| 26 | 1 |  |  | 1 |  | 2 | use UNIVERSAL::DOES; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 210 |  | 
| 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 | 0 |  |  | 0 | 1 |  | my ($class,$hash,$reuse) = @_; | 
| 40 | 0 | 0 |  |  |  |  | if (ref $hash) { | 
| 41 | 0 | 0 |  |  |  |  | return $reuse ? bless $hash, $class | 
| 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 |  |  |  |  |  |  | sub get_member { | 
| 55 | 0 |  |  | 0 | 1 |  | my ($self,$name) = @_; | 
| 56 | 0 | 0 |  |  |  |  | return unless defined $name; | 
| 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 |  |  |  |  |  |  | sub set_member { | 
| 67 | 0 |  |  | 0 | 1 |  | my ($self,$name,$value) = @_; | 
| 68 | 0 | 0 |  |  |  |  | return unless defined $name; | 
| 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 |  |  |  |  |  |  | sub delete_member { | 
| 80 | 0 |  |  | 0 | 1 |  | my ($self,$name) = @_; | 
| 81 | 0 | 0 |  |  |  |  | return unless defined $name; | 
| 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 |  |  |  |  |  |  | sub members { | 
| 92 | 0 |  |  | 0 | 1 |  | return keys %{$_[0]}; | 
|  | 0 |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | } | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =back | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =cut | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | sub DESTROY { | 
| 101 | 0 |  |  | 0 |  |  | my ($self) = @_; | 
| 102 | 0 |  |  |  |  |  | %{$self}=(); # this should not be needed, but | 
|  | 0 |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | # without it, perl 5.10 leaks on weakened | 
| 104 |  |  |  |  |  |  | # structures, try: | 
| 105 |  |  |  |  |  |  | #   Scalar::Util::weaken({}) while 1 | 
| 106 |  |  |  |  |  |  | } | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | 1; | 
| 109 |  |  |  |  |  |  | __END__ |