File Coverage

blib/lib/Treex/PML/Container.pm
Criterion Covered Total %
statement 23 30 76.6
branch 3 6 50.0
condition n/a
subroutine 7 10 70.0
pod 4 4 100.0
total 37 50 74.0


line stmt bran cond sub pod time code
1              
2             =head1 NAME
3              
4             Treex::PML::Container - content and attributes
5              
6             =head1 DESCRIPTION
7              
8             This class implements the data type 'container'. A container consists
9             of a central value called content annotated by a set of name-value
10             pairs called attributes whose values are atomic. Treex::PML represents the
11             container class as a subclass of Treex::PML::Struct, where attributes are
12             represented as members and the content as a member with a reserved
13             name '#content'.
14              
15             =head1 METHODS
16              
17             =over 4
18              
19             =cut
20              
21             package Treex::PML::Container;
22 8     8   60 use Carp;
  8         20  
  8         547  
23 8     8   58 use strict;
  8         264  
  8         268  
24              
25 8     8   42 use vars qw($VERSION);
  8         16  
  8         367  
26             BEGIN {
27 8     8   243 $VERSION='2.28'; # version template
28             }
29 8     8   160 use base qw(Treex::PML::Struct);
  8         27  
  8         3091  
30              
31             =item Treex::PML::Container->new (value?, { name=>attr, ...}?,reuse?)
32              
33             Create a new container (optionally initializing its value and
34             attributes). If reuse is true, the hash reference passed may be
35             reused (re-blessed) into the structure.
36              
37             NOTE: Don't call this constructor directly, use Treex::PML::Factory->createContainer() instead!
38              
39             =cut
40              
41             sub new {
42 207     207 1 501 my ($class,$value,$hash,$reuse) = @_;
43 207 50       444 if (ref $hash) {
44 207 50       480 $hash = {%$hash} unless ($reuse);
45             } else {
46 0         0 $hash = {};
47             }
48 207         390 bless $hash, $class;
49 207 50       704 $hash->{'#content'} = $value unless !defined($value);
50 207         574 return $hash;
51             }
52              
53             =item $container->attributes ()
54              
55             Return (assorted) list of names of all attributes.
56              
57             =cut
58              
59             sub attributes {
60 0     0 1   return grep { $_ ne '#container' } keys %{$_[0]};
  0            
  0            
61             }
62              
63             =item $container->value
64              
65             Return the content value of the container.
66              
67             =cut
68              
69             sub value {
70 0     0 1   return $_[0]->{'#content'};
71             }
72              
73             =item $container->content
74              
75             This is an alias for value().
76              
77             =item $container->set_value($v), $container->set_content($v)
78              
79             Set the central value of the container.
80              
81             =cut
82              
83             sub set_value {
84 0     0 1   my ($self, $value) = @_;
85 0           return $self->{'#content'} = $value
86             }
87              
88             BEGIN{
89 8     8   40 *content = \&value;
90 8         20 *set_content = \&set_value;
91 8         26 *get_attribute = \&Treex::PML::Struct::get_member;
92 8         319 *set_attribute = \&Treex::PML::Struct::set_member;
93             }
94              
95             =item $container->get_attribute($name)
96              
97             Get value of a given attribute. This is just an alias for
98             the inherited C.
99              
100             =item $container->set_attribute($name, $value)
101              
102             Set value of a given attribute. This is just an alias for
103             the inherited C.
104              
105             =back
106              
107             =cut
108              
109             =head1 SEE ALSO
110              
111             L, L, L, L
112              
113             =head1 COPYRIGHT AND LICENSE
114              
115             Copyright (C) 2006-2010 by Petr Pajas, 2010-2024 Jan Stepanek
116              
117             This library is free software; you can redistribute it and/or modify
118             it under the same terms as Perl itself, either Perl version 5.8.2 or,
119             at your option, any later version of Perl 5 you may have available.
120              
121             =cut
122              
123              
124             1;