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