| 1 | package Tree::Template::Declare::DAG_Node; | ||||||||||||
| 2 | { | ||||||||||||
| 3 | 4 | $Tree::Template::Declare::DAG_Node::DIST = 'Tree-Template-Declare'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | 4 | $Tree::Template::Declare::DAG_Node::VERSION = '0.7'; | |||||||||||
| 6 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 4 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 4 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 5 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||
| 11 | 5 | my ($class,$node_class)=@_; | |||||||||||
| 12 | 5 | ▶ | $node_class||='Tree::DAG_Node'; | ||||||||||
|
Condition50%1/2
$node_class ||= "Tree::DAG_Node"
MC/DC0%0/1
$node_class ||= "Tree::DAG_Node"
$node_class
Truth table50%1/2
A
A= $node_class
| |||||||||||||
| 13 | |||||||||||||
| 14 | 5 | ▶ | eval "require $node_class" or ## no critic (ProhibitStringyEval) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 15 | croak "Can't load $node_class: $@"; ## no critic (ProhibitPunctuationVars) | ||||||||||||
| 16 | |||||||||||||
| 17 | 5 | return bless {nc=>$node_class},$class; | |||||||||||
| 18 | } | ||||||||||||
| 19 | |||||||||||||
| 20 | 5 | ▶ | sub new_tree { | ||||||||||
|
Subroutine
new_tree: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 21 | 5 | my ($self)=@_; | |||||||||||
| 22 | |||||||||||||
| 23 | 5 | return bless [],'Tree::Template::Declare::DAG_Node::Tree'; | |||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | 5 | ▶ | sub finalize_tree { | ||||||||||
|
Subroutine
finalize_tree: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 27 | 5 | my ($self,$tree)=@_; | |||||||||||
| 28 | |||||||||||||
| 29 | 5 | return $tree->[0]; | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | 22 | ▶ | sub new_node { | ||||||||||
|
Subroutine
new_node: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 33 | 22 | my ($self)=@_; | |||||||||||
| 34 | |||||||||||||
| 35 | 22 | return $self->{nc}->new(); | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 22 | ▶ | sub add_child_node { | ||||||||||
|
Subroutine
add_child_node: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 39 | 22 | my ($self,$parent,$child)=@_; | |||||||||||
| 40 | |||||||||||||
| 41 | 22 | ▶ | if ($parent->isa('Tree::Template::Declare::DAG_Node::Tree')) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 5 | push @{$parent},$child; | |||||||||||
| 43 | 5 | return $parent; | |||||||||||
| 44 | } | ||||||||||||
| 45 | 17 | return $parent->add_daughter($child); | |||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | 22 | ▶ | sub set_node_name { | ||||||||||
|
Subroutine
set_node_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 49 | 22 | my ($self,$node,$name)=@_; | |||||||||||
| 50 | |||||||||||||
| 51 | 22 | return $node->name($name); | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 11 | ▶ | sub set_node_attributes { | ||||||||||
|
Subroutine
set_node_attributes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 55 | 11 | my ($self,$node,$attrs)=@_; | |||||||||||
| 56 | |||||||||||||
| 57 | my %all_attributes=( | ||||||||||||
| 58 | 11 | %{$node->attributes}, | |||||||||||
| 59 | 11 | %{$attrs}, | |||||||||||
| 60 | ); | ||||||||||||
| 61 | |||||||||||||
| 62 | 11 | return $node->attributes(\%all_attributes); | |||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | 4 | 1; | |||||||||||
| 66 | |||||||||||||
| 67 | =pod | ||||||||||||
| 68 | |||||||||||||
| 69 | =encoding UTF-8 | ||||||||||||
| 70 | |||||||||||||
| 71 | =head1 NAME | ||||||||||||
| 72 | |||||||||||||
| 73 | Tree::Template::Declare::DAG_Node - adaptor for Tree::DAG_Node | ||||||||||||
| 74 | |||||||||||||
| 75 | =head1 VERSION | ||||||||||||
| 76 | |||||||||||||
| 77 | version 0.7 | ||||||||||||
| 78 | |||||||||||||
| 79 | =head1 SYNOPSIS | ||||||||||||
| 80 | |||||||||||||
| 81 | See L<Tree::Template::Declare>. | ||||||||||||
| 82 | |||||||||||||
| 83 | =head1 SPECIFICITIES | ||||||||||||
| 84 | |||||||||||||
| 85 | This module will build trees using L<Tree::DAG_Node>. You can make it | ||||||||||||
| 86 | use another module (assuming it has the same interface, for example | ||||||||||||
| 87 | L<Tree::DAG_Node::XPath>) by passing the class name to the C<new> | ||||||||||||
| 88 | method. | ||||||||||||
| 89 | |||||||||||||
| 90 | use Tree::Template::Declare builder => '+DAG_Node'; # default | ||||||||||||
| 91 | |||||||||||||
| 92 | use Tree::Template::Declare builder => | ||||||||||||
| 93 | Tree::Template::Declare::DAG_Node->new('Tree::DAG_Node::XPath'); | ||||||||||||
| 94 | # custom class | ||||||||||||
| 95 | |||||||||||||
| 96 | =for Pod::Coverage add_child_node finalize_tree new new_node new_tree set_node_attributes set_node_name | ||||||||||||
| 97 | |||||||||||||
| 98 | =head1 AUTHOR | ||||||||||||
| 99 | |||||||||||||
| 100 | Gianni Ceccarelli <dakkar@thenautilus.net> | ||||||||||||
| 101 | |||||||||||||
| 102 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 103 | |||||||||||||
| 104 | This software is copyright (c) 2015 by Gianni Ceccarelli <dakkar@thenautilus.net>. | ||||||||||||
| 105 | |||||||||||||
| 106 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 107 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 108 | |||||||||||||
| 109 | =cut | ||||||||||||
| 110 | |||||||||||||
| 111 | __END__ | ||||||||||||