Catalyst/Outline.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 65 CC 2 SCAR 9.8
CC
2
Cov
0%
populate
6.0
BEGIN
2.0
new
2.0
CRAP 2.7
1 package Padre::Plugin::Catalyst::Outline;
2 BEGIN {
3 $Padre::Plugin::Catalyst::Outline::VERSION = '0.13';
4 }
5  
6 # ABSTRACT: A Catalyst plugin outline
7  
8 use strict;
9 use warnings;
10  
11 use Padre::Wx ();
12 use Wx;
13  
14 use base 'Wx::TreeCtrl';
15  
16 sub new {
17 my $class = shift;
18 my $plugin = shift;
19 my $main = Padre::Current->main;
20  
21 my $self = $class->SUPER::new(
22 $main->right,
23 -1,
24 Wx::wxDefaultPosition,
25 Wx::wxDefaultSize,
26 Wx::wxTR_HIDE_ROOT | Wx::wxTR_SINGLE | Wx::wxTR_HAS_BUTTONS | Wx::wxTR_LINES_AT_ROOT
27 );
28 $self->SetIndent(10);
29 $self->{force_next} = 0;
30  
31 Wx::Event::EVT_COMMAND_SET_FOCUS(
32 $self, $self,
33 sub {
34  
35 # $self->on_tree_item_set_focus( $_[1] );
36 },
37 );
38  
39 # Double-click a function name
40 Wx::Event::EVT_TREE_ITEM_ACTIVATED(
41 $self, $self,
42 sub {
43  
44 # $self->on_tree_item_activated( $_[1] );
45 }
46 );
47  
48 $self->Hide;
49  
50 # $self->Show;
51 $main->right->show($self);
52 $self->fill;
53  
54 return $self;
55 }
56  
57 # fill() fills the TreeCtrl with information regarding the project
58 sub fill {
59 my $self = shift;
60  
61 my $tree_ref = $self->update_tree;
62 my $root = $self->AddRoot( 'Root', -1, -1, Wx::TreeItemData->new('Data') );
63 $self->populate( $root, $tree_ref );
64 }
65  
66 # update_tree() should return whatever it is we want it to fill the
67 # Catalyst side-panel (TreeCtrl) with, as a hash reference.
68 # TODO: I'm still wondering about this Outline. What would you like it
69 # to display?
70 sub update_tree {
71 return {
72 'Model' => {},
73 'View' => {
74 'TT' => 1,
75 },
76 'Controller' => {
77 'Root' => 1,
78 'Foo' => {
79 'Bar' => 1,
80 }
81 },
82 'Templates' => {
83 'one.tt' => 1,
84 'two.tt' => 1,
85 'three.tt' => 1,
86 },
87 };
88 }
89  
90 # receives a hash reference and populates tree (starting from $root node)
91 # with its sorted values, recursively
92 sub populate {
93 my ( $self, $root, $tree_ref ) = (@_);
94  
95 foreach my $item ( sort keys %{$tree_ref} ) {
96 my $node = $self->AppendItem( $root, $item, -1, -1, Wx::TreeItemData->new($item) );
97  
98 if ( ref $tree_ref->{$item} ) {
99 $self->populate( $node, $tree_ref->{$item} );
100 }
101 }
102 }
103  
104 sub gettext_label {
105 Wx::gettext('Catalyst');
106 }
107  
108  
109 1;
110  
111  
112 __END__