File Coverage

blib/lib/Treex/PML/Container.pm
Criterion Covered Total %
statement 22 27 81.4
branch 3 6 50.0
condition n/a
subroutine 7 9 77.7
pod 3 3 100.0
total 35 45 77.7


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 6     6   40 use Carp;
  6         15  
  6         295  
23 6     6   30 use strict;
  6         12  
  6         122  
24              
25 6     6   26 use vars qw($VERSION);
  6         22  
  6         238  
26             BEGIN {
27 6     6   192 $VERSION='2.24'; # version template
28             }
29 6     6   38 use base qw(Treex::PML::Struct);
  6         14  
  6         1570  
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 491 my ($class,$value,$hash,$reuse) = @_;
43 207 50       774 if (ref $hash) {
44 207 50       461 $hash = {%$hash} unless ($reuse);
45             } else {
46 0         0 $hash = {};
47             }
48 207         334 bless $hash, $class;
49 207 50       641 $hash->{'#content'} = $value unless !defined($value);
50 207         562 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             =cut
78              
79             BEGIN{
80 6     6   29 *content = \&value;
81 6         37 *get_attribute = \&Treex::PML::Struct::get_member;
82 6         203 *set_attribute = \&Treex::PML::Struct::set_member;
83             }
84              
85             =item $container->get_attribute($name)
86              
87             Get value of a given attribute. This is just an alias for
88             the inherited C.
89              
90             =item $container->set_attribute($name, $value)
91              
92             Set value of a given attribute. This is just an alias for
93             the inherited C.
94              
95             =back
96              
97             =cut
98              
99             =head1 SEE ALSO
100              
101             L, L, L, L
102              
103             =head1 COPYRIGHT AND LICENSE
104              
105             Copyright (C) 2006-2010 by Petr Pajas
106              
107             This library is free software; you can redistribute it and/or modify
108             it under the same terms as Perl itself, either Perl version 5.8.2 or,
109             at your option, any later version of Perl 5 you may have available.
110              
111             =cut
112              
113              
114             1;