File Coverage

blib/lib/TreePath/Role/Graph.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package TreePath::Role::Graph;
2             $TreePath::Role::Graph::VERSION = '0.01';
3 1     1   25755 use Moose::Role;
  0            
  0            
4             use GraphViz2;
5              
6             requires 'tree';
7              
8             has 'output' => (
9             is => 'rw',
10             default => sub { '/tmp/tpgraph.png' },
11             );
12              
13             sub graph {
14             my $self = shift;
15             my $var = shift;
16              
17             my $g = GraphViz2->new();
18             foreach my $id ( sort { $a <=> $b } keys %{$self->tree}) {
19              
20             my $node = $self->tree->{$id};
21             my $parent = $node->{parent};
22              
23             my @keys = keys %$node;
24             my @keys_children = sort grep {/^children.*/} @keys;
25              
26             my $label_keys_children = '';
27             foreach my $k ( @keys_children ) {
28             $label_keys_children .= "<_${k}_>$k|";
29             }
30             if ( defined $label_keys_children && $label_keys_children ne '') {
31             chop($label_keys_children);
32             $label_keys_children = "{$label_keys_children}|"; #"{c|<here> d|R}";
33             }
34              
35             my $label = "{ $label_keys_children "
36             . $node->{$self->_search_field}
37             . " (". $node->{$self->_type_field} . ")}";
38              
39             $g->add_node( name => $node->{id}, label => $label, shape => 'record', color => 'blue',);
40              
41             if ( $node->{parent} ){
42             my $key_children = $self->_key_children($node, $parent);
43             $g->add_edge( from => $node->{id}, to => "$parent->{id}:_${key_children}_" );
44              
45             }
46             }
47              
48             $g-> run(format => 'png', output_file => $self->output);
49             $self->_log($self->output . " generate.");
50             }
51              
52              
53              
54             =head1 NAME
55              
56             TreePath::Role::Graph - Role to visualize TreePath Graph
57              
58             =head1 VERSION
59              
60             version 0.01
61              
62             =head1 SYNOPSIS
63              
64             package TPGraph;
65             use Moose;
66              
67             extends 'TreePath';
68             with 'TreePath::Role::Graph';
69              
70             1;
71              
72             use TPGraph;
73              
74             # get tree from hash, dbix, file
75             $tp = TPGraph->new( conf => $tree,
76             output => '/tmp/test.png' );
77              
78             $tp->graph; # all the tree
79              
80             $tp->graph($node);
81              
82             =head1 METHODS
83              
84             =head2 graph
85              
86             $tp->graph
87              
88             =cut
89              
90             =head1 SEE ALSO
91              
92             L<TreePath>
93              
94             =cut
95              
96             =head1 AUTHOR
97              
98             Daniel Brosseau, C<< <dab at catapullse.org> >>
99              
100             =head1 BUGS
101              
102             Please report any bugs or feature requests to C<bug-treepath-role-graph at rt.cpan.org>, or through
103             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=TreePath-Role-Graph>. I will be notified, and then you'll
104             automatically be notified of progress on your bug as I make changes.
105              
106              
107              
108              
109             =head1 SUPPORT
110              
111             You can find documentation for this module with the perldoc command.
112              
113             perldoc TreePath::Role::Graph
114              
115              
116             You can also look for information at:
117              
118             =over 4
119              
120             =item * RT: CPAN's request tracker (report bugs here)
121              
122             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=TreePath-Role-Graph>
123              
124             =item * AnnoCPAN: Annotated CPAN documentation
125              
126             L<http://annocpan.org/dist/TreePath-Role-Graph>
127              
128             =item * CPAN Ratings
129              
130             L<http://cpanratings.perl.org/d/TreePath-Role-Graph>
131              
132             =item * Search CPAN
133              
134             L<http://search.cpan.org/dist/TreePath-Role-Graph/>
135              
136             =back
137              
138              
139             =head1 ACKNOWLEDGEMENTS
140              
141              
142             =head1 LICENSE AND COPYRIGHT
143              
144             Copyright 2015 Daniel Brosseau.
145              
146             This program is free software; you can redistribute it and/or modify it
147             under the terms of the the Artistic License (2.0). You may obtain a
148             copy of the full license at:
149              
150             L<http://www.perlfoundation.org/artistic_license_2_0>
151              
152             Any use, modification, and distribution of the Standard or Modified
153             Versions is governed by this Artistic License. By using, modifying or
154             distributing the Package, you accept this license. Do not use, modify,
155             or distribute the Package, if you do not accept this license.
156              
157             If your Modified Version has been derived from a Modified Version made
158             by someone other than you, you are nevertheless required to ensure that
159             your Modified Version complies with the requirements of this license.
160              
161             This license does not grant you the right to use any trademark, service
162             mark, tradename, or logo of the Copyright Holder.
163              
164             This license includes the non-exclusive, worldwide, free-of-charge
165             patent license to make, have made, use, offer to sell, sell, import and
166             otherwise transfer the Package with respect to any patent claims
167             licensable by the Copyright Holder that are necessarily infringed by the
168             Package. If you institute patent litigation (including a cross-claim or
169             counterclaim) against any party alleging that the Package constitutes
170             direct or contributory patent infringement, then this Artistic License
171             to you shall terminate on the date that such litigation is filed.
172              
173             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
174             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
175             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
176             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
177             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
178             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
179             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
180             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
181              
182              
183             =cut
184              
185             1; # End of TreePath::Role::Graph