File Coverage

blib/lib/Treex/Core/Zone.pm
Criterion Covered Total %
statement 9 29 31.0
branch 0 10 0.0
condition 0 3 0.0
subroutine 3 8 37.5
pod 2 5 40.0
total 14 55 25.4


line stmt bran cond sub pod time code
1             package Treex::Core::Zone;
2             $Treex::Core::Zone::VERSION = '2.20150928';
3             # antecedent of DocZone and BundleZone
4              
5 24     24   15271 use Moose;
  24         55  
  24         149  
6 24     24   137540 use Treex::Core::Common;
  24         57  
  24         247  
7 24     24   136197 use MooseX::NonMoose;
  24         17669  
  24         127  
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 0     0 1   my $class = shift;
24 0 0         if ( scalar @_ == 1 ) {
    0          
25 0 0 0       unless ( defined $_[0] && ref $_[0] ) {
26 0           Carp::confess('Single parameter to new() must be a HASH ref');
27             }
28 0           return $_[0];
29             }
30             elsif ( @_ % 2 ) {
31 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           return { ( @_, undef ) };
36             }
37             else {
38 0           return {@_};
39             }
40             }
41              
42             sub FOREIGNBUILDARGS {
43 0     0 0   my $class = shift;
44 0           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 0           return ( $arg_ref, 1 );
49             }
50              
51             sub set_attr {
52 0     0 0   my $self = shift;
53 0           my ( $attr_name, $attr_value ) = pos_validated_list(
54             \@_,
55             { isa => 'Str' },
56             { isa => 'Any' },
57             );
58              
59 0           return $self->{$attr_name} = $attr_value;
60             }
61              
62             sub get_attr {
63 0     0 0   my $self = shift;
64 0           my ($attr_name) = pos_validated_list(
65             \@_,
66             { isa => 'Str' },
67             );
68 0           return $self->{$attr_name};
69             }
70              
71             sub get_label {
72 0 0   0 1   log_fatal 'Incorrect number of arguments' if @_ != 1;
73 0           my $self = shift;
74 0 0         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.20150928
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.