| 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 | 9 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 9 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 9 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 9 | $VERSION='2.29'; # version template | |||||||||
| 28 | } | ||||||||||
| 29 | 9 | ▶ | use base qw(Treex::PML::Struct); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 207 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||
| 42 | 207 | my ($class,$value,$hash,$reuse) = @_; | |||||||||
| 43 | 207 | ▶ | if (ref $hash) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 207 | ▶ | $hash = {%$hash} unless ($reuse); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | } else { | ||||||||||
| 46 | 0 | $hash = {}; | |||||||||
| 47 | } | ||||||||||
| 48 | 207 | bless $hash, $class; | |||||||||
| 49 | 207 | ▶ | $hash->{'#content'} = $value unless !defined($value); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 207 | return $hash; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | =item $container->attributes () | ||||||||||
| 54 | |||||||||||
| 55 | Return (assorted) list of names of all attributes. | ||||||||||
| 56 | |||||||||||
| 57 | =cut | ||||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | sub attributes { | ||||||||
|
Subroutine
attributes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 60 | 0 | return grep { $_ ne '#container' } keys %{$_[0]}; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | =item $container->value | ||||||||||
| 64 | |||||||||||
| 65 | Return the content value of the container. | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | sub value { | ||||||||
|
Subroutine
value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 70 | 0 | 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 | 0 | ▶ | sub set_value { | ||||||||
|
Subroutine
set_value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 84 | 0 | my ($self, $value) = @_; | |||||||||
| 85 | 0 | return $self->{'#content'} = $value | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 9 | ▶ | BEGIN{ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 89 | 9 | *content = \&value; | |||||||||
| 90 | 9 | *set_content = \&set_value; | |||||||||
| 91 | 9 | *get_attribute = \&Treex::PML::Struct::get_member; | |||||||||
| 92 | 9 | *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<Treex::PML::Struct::get_member()>. | ||||||||||
| 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<Treex::PML::Struct::set_member()>. | ||||||||||
| 104 | |||||||||||
| 105 | =back | ||||||||||
| 106 | |||||||||||
| 107 | =cut | ||||||||||
| 108 | |||||||||||
| 109 | =head1 SEE ALSO | ||||||||||
| 110 | |||||||||||
| 111 | L<Treex::PML>, L<Treex::PML::Factory>, L<Treex::PML::Schema>, L<Treex::PML::Struct> | ||||||||||
| 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 | 9 | 1; | |||||||||