File Coverage

blib/lib/Treex/PML/Container.pm
Criterion Covered Total %
statement 16 27 59.2
branch 0 6 0.0
condition n/a
subroutine 6 9 66.6
pod 3 3 100.0
total 25 45 55.5


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 1     1   850 use Carp;
  1         1  
  1         86  
23 1     1   5 use strict;
  1         1  
  1         22  
24              
25 1     1   4 use vars qw($VERSION);
  1         1  
  1         41  
26             BEGIN {
27 1     1   16 $VERSION='2.22'; # version template
28             }
29 1     1   4 use base qw(Treex::PML::Struct);
  1         1  
  1         361  
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 0     0 1   my ($class,$value,$hash,$reuse) = @_;
43 0 0         if (ref $hash) {
44 0 0         $hash = {%$hash} unless ($reuse);
45             } else {
46 0           $hash = {};
47             }
48 0           bless $hash, $class;
49 0 0         $hash->{'#content'} = $value unless !defined($value);
50 0           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 1     1   3 *content = \&value;
81 1         2 *get_attribute = \&Treex::PML::Struct::get_member;
82 1         18 *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;