File Coverage

blib/lib/Wx/Perl/TreeView/SimpleModel.pm
Criterion Covered Total %
statement 6 18 33.3
branch n/a
condition 0 4 0.0
subroutine 2 7 28.5
pod 5 5 100.0
total 13 34 38.2


line stmt bran cond sub pod time code
1             package Wx::Perl::TreeView::SimpleModel;
2              
3             =head1 NAME
4              
5             Wx::Perl::TreeView::SimpleModel - virtual tree control simple model class
6              
7             =head1 DESCRIPTION
8              
9             A simple model class for C.
10              
11             =head1 METHODS
12              
13             =cut
14              
15 1     1   1507 use strict;
  1         3  
  1         46  
16 1     1   5 use base qw(Wx::Perl::TreeView::Model);
  1         1  
  1         713  
17              
18             =head2 new
19              
20             my $model = Wx::Perl::TreeView::SimpleModel->new( $data );
21              
22             Where C<$data> has the following structure:
23              
24             { node => 'label',
25             childs => [ { ... },
26             { ... },
27             ],
28             }
29              
30             =cut
31              
32             sub new {
33 0     0 1   my( $class, $data ) = @_;
34 0           my $self = bless { data => $data }, $class;
35              
36 0           return $self;
37             }
38              
39             sub get_root {
40 0     0 1   my( $self ) = @_;
41              
42 0           return ( $self->data, $self->data->{node}, undef, $self->data->{data} );
43             }
44              
45             sub get_child_count {
46 0     0 1   my( $self, $cookie ) = @_;
47 0   0       my $childs = $cookie->{childs} || [];
48              
49 0           return scalar @$childs;
50             }
51              
52             sub get_child {
53 0     0 1   my( $self, $cookie, $index ) = @_;
54 0   0       my $childs = $cookie->{childs} || [];
55              
56 0           return ( $childs->[$index], $childs->[$index]->{node}, undef,
57             $childs->[$index]->{data} );
58             }
59              
60             =head2 data
61              
62             my $data = $self->data;
63              
64             Accessor for the model data.
65              
66             =cut
67              
68 0     0 1   sub data { $_[0]->{data} }
69              
70             1;