| 1 | package YAX::Node; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 3 | ▶ | use Scalar::Util qw/weaken refaddr/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 3 | ▶ | use YAX::Query; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use YAX::Constants qw/:all/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | use overload | ||||||||||
| 11 | 3 | ▶ | '""' => \&as_string, | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | '<=>' => \&num_cmp, | ||||||||||
| 13 | 'bool' => \&as_bool, | ||||||||||
| 14 | 3 | fallback => 1; | |||||||||
| 15 | |||||||||||
| 16 | sub NAME () { 0 } | ||||||||||
| 17 | sub TYPE () { 1 } | ||||||||||
| 18 | sub TEXT () { 2 } | ||||||||||
| 19 | sub PRNT () { 3 } | ||||||||||
| 20 | |||||||||||
| 21 | 5 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 22 | 5 | my $class = shift; | |||||||||
| 23 | 5 | return bless \[ @_ ], $class; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 28 | ▶ | sub name { | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 27 | 28 | my $self = shift; | |||||||||
| 28 | 28 | $$self->[NAME] | |||||||||
| 29 | } | ||||||||||
| 30 | 7 | ▶ | sub type { | ||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 31 | 7 | my $self = shift; | |||||||||
| 32 | 7 | $$self->[TYPE]; | |||||||||
| 33 | } | ||||||||||
| 34 | 3 | ▶ | sub data { | ||||||||
|
Subroutine
data: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 35 | 3 | my $self = shift; | |||||||||
| 36 | 3 | ▶ | $$self->[TEXT] = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 3 | $$self->[TEXT]; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 5 | ▶ | sub parent { | ||||||||
|
Subroutine
parent: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 41 | 5 | my $self = shift; | |||||||||
| 42 | 5 | ▶ | weaken( $$self->[PRNT] = $_[0] ) if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 5 | $$self->[PRNT]; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | sub num_cmp { | ||||||||
|
Subroutine
num_cmp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 47 | 0 | my ( $a, $b ) = @_; | |||||||||
| 48 | 0 | refaddr( $a ) <=> refaddr( $b ); | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub next { | ||||||||
|
Subroutine
next: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 52 | 0 | my $self = shift; | |||||||||
| 53 | 0 | ▶ | return undef unless $self->parent; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | ▶ | return undef if $self->parent->[-1] == $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 0 | ▶ | for ( my $x = 0; $x < @{ $self->parent }; $x++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | ▶ | if ( $self == $self->parent->[$x] ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | return $self->parent->[$x+1]; | |||||||||
| 58 | } | ||||||||||
| 59 | } | ||||||||||
| 60 | 0 | return undef; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | sub prev { | ||||||||
|
Subroutine
prev: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 64 | 0 | my $self = shift; | |||||||||
| 65 | 0 | ▶ | return undef unless $self->parent; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | ▶ | return undef if $self->parent->[0] == $self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | ▶ | for ( my $x = 0; $x < @{ $self->parent }; $x++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | ▶ | if ( $self == $self->parent->[$x] ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | return $self->parent->[$x-1]; | |||||||||
| 70 | } | ||||||||||
| 71 | } | ||||||||||
| 72 | 0 | return undef; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 3 | ▶ | sub document { | ||||||||
|
Subroutine
document: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 76 | 3 | my $self = shift; | |||||||||
| 77 | 3 | my $root = $self; | |||||||||
| 78 | 3 | ▶ | while ( $root->parent ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 6 | $root = $root->parent; | |||||||||
| 80 | 6 | ▶ | return $root if $root->type == DOCUMENT_NODE; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | } | ||||||||||
| 82 | 0 | return ( ); | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 2 | ▶ | sub as_string { | ||||||||
|
Subroutine
as_string: called CC=4 SCAR=18.7
Pod
documented
| |||||||||||
| 86 | 2 | my $self = shift; | |||||||||
| 87 | 2 | ▶ | if ( $self->type == COMMENT_NODE ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 0 | return '<!--'.$self->data.'-->'; | |||||||||
| 89 | } | ||||||||||
| 90 | 2 | ▶ | if ( $self->type == CDATA_SECTION_NODE ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 2 | return '<![CDATA['.$self->data.']]>'; | |||||||||
| 92 | } | ||||||||||
| 93 | 0 | ▶ | if ( $self->type == PROCESSING_INSTRUCTION_NODE ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 0 | return '<?'.$self->name.' '.$self->data.' ?>'; | |||||||||
| 95 | } | ||||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | # prevent stringification when in a boolean context | ||||||||||
| 99 | 9 | ▶ | sub as_bool { 1 } | ||||||||
|
Subroutine
as_bool: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 100 | |||||||||||
| 101 | 3 | 1; | |||||||||
| 102 | __END__ | ||||||||||