Declare/HTML_Element.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 7 totaltotal 90.1% 64 / 71 CC 3 SCAR 2.2
CC
3
Cov
100%
add_child_node
2.0
set_node_attributes
2.0
BEGIN
1.0
CRAP 1.2
« Declare/DAG_Node.pm ↑ Summary
1 package Tree::Template::Declare::HTML_Element;
2 {
3 1 $Tree::Template::Declare::HTML_Element::DIST = 'Tree-Template-Declare';
4 }
5 1 $Tree::Template::Declare::HTML_Element::VERSION = '0.7';
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use HTML::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
12 1 my ($class)=@_;
13  
14 1 return bless {},$class;
15 }
16  
17 1 ▶sub _munge_exports {
Subroutine _munge_exports: called CC=1 SCAR=0.0
18 1 my ($self,$exports)=@_;
19  
20 my %all_exports=(
21 1 %{$exports},
22 2 ▶ text_node => sub($) {
Subroutine __ANON__: called CC=1 SCAR=0.0
23 $exports->{node}->(
24 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
25 2 $exports->{name}->('~text');
26 2 $exports->{attribs}->(text => $_[0]);
27 2 });
28 },
29 1 );
30  
31 1 return \%all_exports;
32 }
33  
34 1 ▶sub new_tree {
Subroutine new_tree: called CC=1 SCAR=0.0
Pod undocumented
35 1 my ($self)=@_;
36  
37 1 return bless [],'Tree::Template::Declare::HTML_Element::Tree';
38 }
39  
40 1 ▶sub finalize_tree {
Subroutine finalize_tree: called CC=1 SCAR=0.0
Pod undocumented
41 1 my ($self,$tree)=@_;
42  
43 1 my $dom=$tree->[0];
44 1 $dom->deobjectify_text();
45 1 return $dom;
46 }
47  
48 7 ▶sub new_node {
Subroutine new_node: called CC=1 SCAR=0.0
Pod undocumented
49 7 my ($self)=@_;
50  
51 7 return HTML::Element->new('~comment');
52 }
53  
54 7 ▶sub add_child_node {
Subroutine add_child_node: called CC=2 SCAR=6.9
Pod undocumented
55 7 my ($self,$parent,$child)=@_;
56  
57  
58 7 ▶ if ($parent->isa('Tree::Template::Declare::HTML_Element::Tree')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->isa("Tree::Template::Declare::HTML_Element::Tree")) 1 6 7
59 1 push @{$parent},$child;
60 1 return $parent;
61 }
62 6 return $parent->push_content($child);
63 }
64  
65 7 ▶sub set_node_name {
Subroutine set_node_name: called CC=1 SCAR=0.0
Pod undocumented
66 7 my ($self,$node,$name)=@_;
67  
68 7 return $node->tag($name);
69 }
70  
71 4 ▶sub set_node_attributes {
Subroutine set_node_attributes: called CC=2 SCAR=6.9
Pod undocumented
72 4 my ($self,$node,$attrs)=@_;
73  
74 4 ▶ while (my ($name,$val)=each %{$attrs}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$attrs;}) 4 4 8
75 4 $node->attr($name, $val);
76 }
77 4 return;
78 }
79  
80 1 1;
81  
82 =pod
83  
84 =encoding UTF-8
85  
86 =head1 NAME
87  
88 Tree::Template::Declare::HTML_Element - adaptor for HTML::Element
89  
90 =head1 VERSION
91  
92 version 0.7
93  
94 =head1 SYNOPSIS
95  
96 See L<Tree::Template::Declare>.
97  
98 =head1 SPECIFICITIES
99  
100 This module will build trees using L<HTML::Element>.
101  
102 To create text nodes, you would be forced to say:
103  
104 node {
105 name '~text';
106 attribs text => 'some text';
107 }
108  
109 which is too cumbersone. You can instead use:
110  
111 text_node 'some text';
112  
113 HTML::Element's C<deobjectify_text> method will be called by
114 C<finalize_tree> before returning the tree object.
115  
116 =for Pod::Coverage add_child_node finalize_tree new new_node new_tree set_node_attributes set_node_name
117  
118 =head1 AUTHOR
119  
120 Gianni Ceccarelli <dakkar@thenautilus.net>
121  
122 =head1 COPYRIGHT AND LICENSE
123  
124 This software is copyright (c) 2015 by Gianni Ceccarelli <dakkar@thenautilus.net>.
125  
126 This is free software; you can redistribute it and/or modify it under
127 the same terms as the Perl 5 programming language system itself.
128  
129 =cut
130  
131 __END__
« Declare/DAG_Node.pm ↑ Summary