File Coverage

blib/lib/Treex/Core/Zone.pm
Criterion Covered Total %
statement 25 29 86.2
branch 5 10 50.0
condition 1 3 33.3
subroutine 8 8 100.0
pod 2 5 40.0
total 41 55 74.5


line stmt bran cond sub pod time code
1             package Treex::Core::Zone;
2             $Treex::Core::Zone::VERSION = '2.20210102';
3             # antecedent of DocZone and BundleZone
4              
5 24     24   14677 use Moose;
  24         72  
  24         161  
6 24     24   159491 use Treex::Core::Common;
  24         71  
  24         221  
7 24     24   150799 use MooseX::NonMoose;
  24         22497  
  24         131  
8              
9             extends 'Treex::PML::Struct';
10              
11             has language => ( is => 'rw', isa => 'Treex::Type::LangCode', required => 1 );
12              
13             has selector => ( is => 'rw', isa => 'Treex::Type::Selector', default => '' );
14              
15             # Based on source code of Moose::Object::BUILDARGS,
16             # but we don't want to copy args (return { %{$_[0]} };).
17             # The motivation for this is that we want
18             # to enable "Moose-aware reblessing" of Treex::PML::Struct
19             # foreach my $zone ( map { $_->value() } $bundle->{zones}->elements ) {
20             # Treex::Core::BundleZone->new($zone);
21             # ...
22             sub BUILDARGS {
23 110     110 1 629 my $class = shift;
24 110 50       303 if ( scalar @_ == 1 ) {
    0          
25 110 50 33     545 unless ( defined $_[0] && ref $_[0] ) {
26 0         0 Carp::confess('Single parameter to new() must be a HASH ref');
27             }
28 110         302 return $_[0];
29             }
30             elsif ( @_ % 2 ) {
31 0         0 Carp::carp(
32             "The new() method for $class expects a hash reference or a key/value list."
33             . " You passed an odd number of arguments"
34             );
35 0         0 return { ( @_, undef ) };
36             }
37             else {
38 0         0 return {@_};
39             }
40             }
41              
42             sub FOREIGNBUILDARGS {
43 55     55 0 672 my $class = shift;
44 55         187 my $arg_ref = $class->BUILDARGS(@_);
45              
46             # We want to reuse the $arg_ref hashref as the blessed instance variable, i.e.
47             # $reuse = 1; Treex::PML::Struct->new( $arg_ref, $reuse )
48 55         207 return ( $arg_ref, 1 );
49             }
50              
51             sub set_attr {
52 53     53 0 134 my $self = shift;
53 53         316 my ( $attr_name, $attr_value ) = pos_validated_list(
54             \@_,
55             { isa => 'Str' },
56             { isa => 'Any' },
57             );
58              
59 53         248 return $self->{$attr_name} = $attr_value;
60             }
61              
62             sub get_attr {
63 1289     1289 0 2047 my $self = shift;
64 1289         5962 my ($attr_name) = pos_validated_list(
65             \@_,
66             { isa => 'Str' },
67             );
68 1289         8280 return $self->{$attr_name};
69             }
70              
71             sub get_label {
72 78 50   78 1 254 log_fatal 'Incorrect number of arguments' if @_ != 1;
73 78         137 my $self = shift;
74 78 100       2256 return $self->language . ( $self->selector ? '_' . $self->selector : '' );
75             }
76             1;
77              
78             __END__
79              
80              
81             =for Pod::Coverage BUILDARGS FOREIGNBUILDARGS set_attr get_attr
82              
83             =encoding utf-8
84              
85             =head1 NAME
86              
87             Treex::Core::Zone - base class for Zones
88              
89             =head1 VERSION
90              
91             version 2.20210102
92              
93             =head1 DESCRIPTION
94              
95             C<Treex::Core::Zone> is an abstract class, it is the antecedent
96             of L<Treex::Core::DocZone> and
97             L<Treex::Core::BundleZone>.
98              
99             =head1 ATTRIBUTES
100              
101             C<Treex::Core::Zone> instances have the following attributes:
102              
103             =over 4
104              
105             =item language
106              
107             =item selector
108              
109             =back
110              
111             =head1 METHODS
112              
113             =over 4
114              
115             =item $my $label = $zone->get_label;
116              
117             I<Zone label> is a string containing the zone's language
118             and selector concatenated with 'C<_>'(if the latter one is defined,
119             otherwise only the language).
120              
121             =back
122              
123             =head1 AUTHOR
124              
125             Zdeněk Žabokrtský <zabokrtsky@ufal.mff.cuni.cz>
126              
127             Martin Popel <popel@ufal.mff.cuni.cz>
128              
129             =head1 COPYRIGHT AND LICENSE
130              
131             Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague
132              
133             This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.