| 1 | package Treex::Core::Zone; | ||||||||||||||||||||||||||||
| 2 | 37 | $Treex::Core::Zone::VERSION = '2.20151210'; | |||||||||||||||||||||||||||
| 3 | # antecedent of DocZone and BundleZone | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 37 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 37 | ▶ | use Treex::Core::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 37 | ▶ | use MooseX::NonMoose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 37 | extends 'Treex::PML::Struct'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 37 | has language => ( is => 'rw', isa => 'Treex::Type::LangCode', required => 1 ); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 37 | 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 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=5 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 110 | ▶ | if ( scalar @_ == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 25 | 110 | ▶ | unless ( defined $_[0] && ref $_[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_[0] and ref $_[0]
MC/DC0%0/2
defined $_[0] and ref $_[0]
defined $_[0]
ref $_[0]
Truth table33%1/3
A and B
A= defined $_[0]B= ref $_[0]
| |||||||||||||||||||||||||||||
| 26 | 0 | Carp::confess('Single parameter to new() must be a HASH ref'); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | 110 | 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 | 55 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
FOREIGNBUILDARGS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 55 | 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 | return ( $arg_ref, 1 ); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub set_attr { | ||||||||||||||||||||||||||||
| 52 | 53 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
set_attr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 53 | my ( $attr_name, $attr_value ) = pos_validated_list( | |||||||||||||||||||||||||||
| 54 | \@_, | ||||||||||||||||||||||||||||
| 55 | { isa => 'Str' }, | ||||||||||||||||||||||||||||
| 56 | { isa => 'Any' }, | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 53 | return $self->{$attr_name} = $attr_value; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub get_attr { | ||||||||||||||||||||||||||||
| 63 | 1244 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_attr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 1244 | my ($attr_name) = pos_validated_list( | |||||||||||||||||||||||||||
| 65 | \@_, | ||||||||||||||||||||||||||||
| 66 | { isa => 'Str' }, | ||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||
| 68 | 1244 | return $self->{$attr_name}; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub get_label { | ||||||||||||||||||||||||||||
| 72 | 78 | ▶ | log_fatal 'Incorrect number of arguments' if @_ != 1; | ||||||||||||||||||||||||||
|
Subroutine
get_label: called CC=3 SCAR=11.1
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 78 | my $self = shift; | |||||||||||||||||||||||||||
| 74 | 78 | ▶ | return $self->language . ( $self->selector ? '_' . $self->selector : '' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 37 | 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.20151210 | ||||||||||||||||||||||||||||
| 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. | ||||||||||||||||||||||||||||