| 1 | #!/usr/bin/perl -w | ||||||||||||||
| 2 | |||||||||||||||
| 3 | package Lingua::Phonology::Segment::Tier; | ||||||||||||||
| 4 | |||||||||||||||
| 5 | 8 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 8 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 8 | ▶ | use warnings::register; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 8 | ▶ | use Lingua::Phonology::Common; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 8 | our $VERSION = 0.11; | |||||||||||||
| 11 | |||||||||||||||
| 12 | 0 | ▶ | sub err ($) { _err($_[0]) if warnings::enabled() }; | ||||||||||||
|
Subroutine
err: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | 135 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||
| 15 | 135 | my $proto = shift; | |||||||||||||
| 16 | |||||||||||||||
| 17 | # When called as an object method, return a regular segment | ||||||||||||||
| 18 | 135 | ▶ | return $proto->[0]->new(@_) if ref $proto; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 19 | |||||||||||||||
| 20 | 135 | ▶ | return err "No segments given for pseudo-segment" if not @_; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | 135 | for (@_) { | |||||||||||||
| 22 | 141 | ▶ | _is_seg $_ or return; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 23 | } | ||||||||||||||
| 24 | 135 | bless \@_, $proto; | |||||||||||||
| 25 | } | ||||||||||||||
| 26 | |||||||||||||||
| 27 | |||||||||||||||
| 28 | # all_values() always returns the value C<< ( PSEUDO => 1 ) >>. This is mostly | ||||||||||||||
| 29 | # just useful to help Lingua::Phonology::Rules, so that it doesn't think that | ||||||||||||||
| 30 | # pseudo-segments are blank. | ||||||||||||||
| 31 | |||||||||||||||
| 32 | 0 | ▶ | sub all_values { | ||||||||||||
|
Subroutine
all_values: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 33 | 0 | return ( PSEUDO => 1 ); | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | # This method ensures that we pass method calls to all encapsulated segs, but | ||||||||||||||
| 37 | # only return if all segs returned the same thing | ||||||||||||||
| 38 | 8 | our $AUTOLOAD; | |||||||||||||
| 39 | 282 | ▶ | sub AUTOLOAD { | ||||||||||||
|
Subroutine
AUTOLOAD: called CC=14 SCAR=33.6
| |||||||||||||||
| 40 | 282 | my $self = shift; | |||||||||||||
| 41 | 282 | my $method = $AUTOLOAD; | |||||||||||||
| 42 | 282 | $method =~ s/.*:://; | |||||||||||||
| 43 | |||||||||||||||
| 44 | # Pass everything through to the segments | ||||||||||||||
| 45 | 282 | my ($return, $disagree); | |||||||||||||
| 46 | 282 | for (@$self) { | |||||||||||||
| 47 | 8 | ▶ | no warnings 'uninitialized'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 48 | |||||||||||||||
| 49 | # Return value from current member of $self | ||||||||||||||
| 50 | 294 | my $this; | |||||||||||||
| 51 | |||||||||||||||
| 52 | # The following blocks ensure that we provide the proper context to the | ||||||||||||||
| 53 | # method calls | ||||||||||||||
| 54 | |||||||||||||||
| 55 | # Array context | ||||||||||||||
| 56 | 294 | ▶ | if (wantarray) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 57 | 0 | $this = [ $_->$method(@_) ]; | |||||||||||||
| 58 | 0 | ▶ | next if $disagree; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | |||||||||||||||
| 60 | 0 | ▶ | if (not $return) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 61 | 0 | $return = $this; | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | # Check that we're the same for every element of the returned list | ||||||||||||||
| 64 | else { | ||||||||||||||
| 65 | 0 | ▶ | if (@$this != @$return) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 66 | 0 | $disagree = 1; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | else { | ||||||||||||||
| 70 | 0 | for (0 .. $#{$this}) { | |||||||||||||
| 71 | 0 | ▶ | if ($this->[$_] ne $return->[$_]) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 72 | 0 | $disagree = 1; | |||||||||||||
| 73 | 0 | last; | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | } | ||||||||||||||
| 76 | } | ||||||||||||||
| 77 | } | ||||||||||||||
| 78 | } | ||||||||||||||
| 79 | |||||||||||||||
| 80 | # Scalar context | ||||||||||||||
| 81 | elsif (defined wantarray) { | ||||||||||||||
| 82 | 270 | $this = $_->$method(@_); | |||||||||||||
| 83 | 270 | ▶ | next if $disagree; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 84 | |||||||||||||||
| 85 | 270 | ▶ | if (not defined $return) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 86 | 262 | $return = $this; | |||||||||||||
| 87 | } | ||||||||||||||
| 88 | else { | ||||||||||||||
| 89 | 8 | ▶ | $disagree = 1 if $return ne $this; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 90 | } | ||||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | # Void context | ||||||||||||||
| 94 | else { | ||||||||||||||
| 95 | 24 | $_->$method(@_); | |||||||||||||
| 96 | } | ||||||||||||||
| 97 | |||||||||||||||
| 98 | } | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 282 | ▶ | return if $disagree; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 101 | 281 | ▶ | return @$return if wantarray; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 102 | 281 | return $return; | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | # Don't pass on DESTROY | ||||||||||||||
| 106 | 0 | ▶ | sub DESTROY {} | ||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||
| 107 | |||||||||||||||
| 108 | 8 | 1; | |||||||||||||