| 1 | package YAX::Element; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use base qw/YAX::Node/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use YAX; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use YAX::Query; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use YAX::Constants qw/ELEMENT_NODE/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Scalar::Util qw/weaken/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | use overload | ||||||||||||||||||||||||||||
| 15 | 3 | ▶ | '@{}' => \&children, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | '%{}' => \&attributes, | ||||||||||||||||||||||||||||
| 17 | '""' => \&as_string, | ||||||||||||||||||||||||||||
| 18 | 3 | fallback => 1; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub NAME () { 0 } | ||||||||||||||||||||||||||||
| 21 | sub ATTR () { 1 } | ||||||||||||||||||||||||||||
| 22 | sub KIDS () { 2 } | ||||||||||||||||||||||||||||
| 23 | sub PRNT () { 3 } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 32 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 32 | my $class = shift; | |||||||||||||||||||||||||||
| 27 | 32 | my ( $name, %atts ) = @_; | |||||||||||||||||||||||||||
| 28 | 32 | my $self = bless \[ $name, \%atts, [ ] ], $class; | |||||||||||||||||||||||||||
| 29 | 32 | $self; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 9 | ▶ | sub type { ELEMENT_NODE() } | ||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 259 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 259 | my $self = shift; | |||||||||||||||||||||||||||
| 36 | 259 | ▶ | $$self->[NAME] = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 259 | $$self->[NAME]; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 42 | 0 | my $deep = shift; | |||||||||||||||||||||||||||
| 43 | 0 | my $copy = ref( $self )->new( $self->name, %$self ); | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | @$copy = map { $_->clone( $deep ) } @$self if $deep; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | return $copy; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 14 | ▶ | sub query { | ||||||||||||||||||||||||||
|
Subroutine
query: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 14 | my ( $self, $expr ) = @_; | |||||||||||||||||||||||||||
| 50 | 14 | YAX::Query->new( $self )->select( $expr ); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 48 | ▶ | sub parent { | ||||||||||||||||||||||||||
|
Subroutine
parent: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 48 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 48 | ▶ | weaken( $$self->[PRNT] = $_[0] ) if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 48 | $$self->[PRNT]; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 342 | ▶ | sub children { | ||||||||||||||||||||||||||
|
Subroutine
children: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 342 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 342 | $$self->[KIDS]; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 76 | ▶ | sub attributes { | ||||||||||||||||||||||||||
|
Subroutine
attributes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 76 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 76 | $$self->[ATTR]; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 6 | ▶ | sub append { | ||||||||||||||||||||||||||
|
Subroutine
append: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 71 | 6 | my $node = shift; | |||||||||||||||||||||||||||
| 72 | 6 | ▶ | if ( UNIVERSAL::isa( $node, 'YAX::Fragment' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | $self->append( $_ ) for @$node; | |||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||
| 75 | 6 | push @$self, $self->adopt( $node ); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 6 | $#$self; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub replace { | ||||||||||||||||||||||||||
|
Subroutine
replace: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 0 | my ( $self, $new, $ref ) = @_; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | for ( my $x = 0; $x < @$self; $x++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ( $self->[$x] == $ref ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( UNIVERSAL::isa( $new, 'YAX::Fragment' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | splice( @$self, $x, 1, map { $self->adopt( $_) } @$new ); | |||||||||||||||||||||||||||
| 87 | } else { | ||||||||||||||||||||||||||||
| 88 | 0 | splice( @$self, $x, 1, $self->adopt( $new ) ); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | return $x; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub remove { | ||||||||||||||||||||||||||
|
Subroutine
remove: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 0 | my ( $self, $chld ) = @_; | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | return unless $chld->parent == $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | for ( my $x = 0; $x < @$self; $x++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( $self->[$x] == $chld ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | splice( @$self, $x, 1 ); | |||||||||||||||||||||||||||
| 101 | 0 | $chld->parent( undef ); | |||||||||||||||||||||||||||
| 102 | 0 | return $x; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub insert { | ||||||||||||||||||||||||||
|
Subroutine
insert: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 0 | my ( $self, $new, $ref ) = @_; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | unless ( defined $ref ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ( UNIVERSAL::isa( $new, 'YAX::Fragment' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | unshift( @$self, map { $self->adopt( $_ ) } @$new ); | |||||||||||||||||||||||||||
| 113 | } else { | ||||||||||||||||||||||||||||
| 114 | 0 | unshift( @$self, $self->adopt( $new ) ); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 0 | return 0; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | for ( my $x = 0; $x < @$self; $x++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ( $self->[$x] == $ref ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( UNIVERSAL::isa( $new, 'YAX::Fragment' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | splice( @$self, $x, 0, map { $self->adopt( $_ ) } @$new ); | |||||||||||||||||||||||||||
| 123 | } else { | ||||||||||||||||||||||||||||
| 124 | 0 | splice( @$self, $x, 0, $self->adopt( $new ) ); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 0 | return $x; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 6 | ▶ | sub adopt { | ||||||||||||||||||||||||||
|
Subroutine
adopt: called CC=4 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | 6 | my ( $self, $node ) = @_; | |||||||||||||||||||||||||||
| 133 | 6 | ▶ | unless ( UNIVERSAL::isa( $node, 'YAX::Node' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | Carp::croak( "cannot insert `$node' into the document tree" ); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | 6 | my $prnt = $node->parent; | |||||||||||||||||||||||||||
| 137 | 6 | ▶ | if ( defined $prnt and $prnt != $self ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $prnt and $prnt != $self
MC/DC0%0/2
defined $prnt and $prnt != $self
defined $prnt
$prnt != $self
Truth table33%1/3
A and B
A= defined $prntB= $prnt != $self
| |||||||||||||||||||||||||||||
| 138 | 0 | $prnt->remove( $node ); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 6 | $node->parent( $self ); | |||||||||||||||||||||||||||
| 141 | 6 | return $node; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 2 | ▶ | sub as_string { | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 145 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 146 | 2 | my $name = $self->name; | |||||||||||||||||||||||||||
| 147 | 2 | my $atts = $self->attributes_as_string; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 2 | ▶ | return "<$name $atts />" unless @{ $self->children }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 2 | my $kids = $self->children_as_string; | |||||||||||||||||||||||||||
| 152 | 2 | ▶ | return "<$name".( $atts ? " $atts" : '' ).">".$kids."</$name>"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 2 | ▶ | sub attributes_as_string { | ||||||||||||||||||||||||||
|
Subroutine
attributes_as_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 156 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 157 | return join(' ', map { | ||||||||||||||||||||||||||||
| 158 | 2 | $_.'="'.quote( $self->{$_} ).'"' | |||||||||||||||||||||||||||
| 159 | } keys %$self); | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 2 | ▶ | sub children_as_string { | ||||||||||||||||||||||||||
|
Subroutine
children_as_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 164 | 2 | join( '', map { $_->as_string } @{ $self->children } ); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 4 | ▶ | sub quote { | ||||||||||||||||||||||||||
|
Subroutine
quote: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 168 | 4 | my $str = pop; | |||||||||||||||||||||||||||
| 169 | 4 | $str =~ s/"/"/gs; | |||||||||||||||||||||||||||
| 170 | 4 | $str; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 3 | 1; | |||||||||||||||||||||||||||
| 174 | __END__ | ||||||||||||||||||||||||||||