line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::AsGraph; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
32022
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
2864
|
use Graph::Easy; |
|
1
|
|
|
|
|
184427
|
|
|
1
|
|
|
|
|
49
|
|
6
|
1
|
|
|
1
|
|
3329
|
use Template; |
|
1
|
|
|
|
|
41309
|
|
|
1
|
|
|
|
|
38
|
|
7
|
1
|
|
|
1
|
|
12
|
use Carp 'croak'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
50
|
|
8
|
1
|
|
|
1
|
|
6
|
use File::Spec; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
337
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub graph { |
14
|
|
|
|
|
|
|
# get parameters |
15
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
16
|
0
|
0
|
|
|
|
|
my $filename = shift or croak "you must specify a template name"; |
17
|
0
|
0
|
|
|
|
|
my $config = (@_ ? shift : {}); |
18
|
0
|
0
|
|
|
|
|
my $vars = (@_ ? shift : {}); |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
|
unless (exists $config->{OUTPUT}) { |
21
|
0
|
|
0
|
|
|
|
$config->{OUTPUT} ||= File::Spec->devnull; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# setup our own context object. This can be |
25
|
|
|
|
|
|
|
# overridable by user's $config, assuming |
26
|
|
|
|
|
|
|
# they know what they're doing |
27
|
0
|
|
|
|
|
|
$Template::Config::CONTEXT = 'Template::AsGraph::Context'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# process the given template, to populate |
30
|
|
|
|
|
|
|
# context's tree structure |
31
|
0
|
|
|
|
|
|
my $template = Template->new($config); |
32
|
0
|
0
|
|
|
|
|
$template->process($filename, $vars) |
33
|
|
|
|
|
|
|
|| croak $template->error; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# grab our shiny tree and make it a graph! |
36
|
0
|
|
|
|
|
|
my $tree = $template->context->tree; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $graph = Graph::Easy->new(); |
39
|
0
|
|
|
|
|
|
foreach my $child (keys %{$tree}) { |
|
0
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
_new_node($graph, $filename, $tree->{$child}); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return $graph; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# this internal method recursively fills |
48
|
|
|
|
|
|
|
# our graph with appropriate node values |
49
|
|
|
|
|
|
|
sub _new_node { |
50
|
0
|
|
|
0
|
|
|
my ($graph, $name, $tree) = (@_); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# add current node to graph |
53
|
0
|
|
|
|
|
|
my $node = $graph->add_node($name); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# link each child to it |
56
|
0
|
|
|
|
|
|
foreach my $child (keys %{$tree}) { |
|
0
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $child_node = _new_node($graph, $child, $tree->{$child}); |
58
|
0
|
|
|
|
|
|
$graph->add_edge($node, $child_node); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $node; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
42; |
65
|
|
|
|
|
|
|
__END__ |