| 1 | package Treex::Core::Zone; | ||||||||||||||||||||||||||||
| 2 | 37 | $Treex::Core::Zone::VERSION = '2.20210102'; | |||||||||||||||||||||||||||
| 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 | 110 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=5 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 110 | my $class = shift; | |||||||||||||||||||||||||||
| 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 | 55 | ▶ | sub FOREIGNBUILDARGS { | ||||||||||||||||||||||||||
|
Subroutine
FOREIGNBUILDARGS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 55 | my $class = shift; | |||||||||||||||||||||||||||
| 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 | 53 | ▶ | sub set_attr { | ||||||||||||||||||||||||||
|
Subroutine
set_attr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 53 | my $self = shift; | |||||||||||||||||||||||||||
| 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 | 1289 | ▶ | sub get_attr { | ||||||||||||||||||||||||||
|
Subroutine
get_attr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 1289 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | 1289 | my ($attr_name) = pos_validated_list( | |||||||||||||||||||||||||||
| 65 | \@_, | ||||||||||||||||||||||||||||
| 66 | { isa => 'Str' }, | ||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||
| 68 | 1289 | return $self->{$attr_name}; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 78 | ▶ | sub get_label { | ||||||||||||||||||||||||||
|
Subroutine
get_label: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 78 | ▶ | log_fatal 'Incorrect number of arguments' if @_ != 1; | ||||||||||||||||||||||||||
|
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__ | ||||||||||||||||||||||||||||