File Coverage

lib/Devel/ebug/Wx/View/Eval.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Devel::ebug::Wx::View::Eval;
2              
3 1     1   879 use strict;
  1         39  
  1         34  
4 1         639 use base qw(Wx::Panel Devel::ebug::Wx::View::Base
5 1     1   5 Devel::ebug::Wx::Plugin::Configurable::Base);
  1         1  
6             use Devel::ebug::Wx::Plugin qw(:plugin);
7              
8             __PACKAGE__->mk_accessors( qw(display input display_mode) );
9              
10             use Wx qw(:textctrl :sizer);
11             use Wx::Event qw(EVT_BUTTON);
12              
13             sub tag { 'eval' }
14             sub description { 'Eval' }
15              
16             sub new : View {
17             my( $class, $parent, $wxebug, $layout_state ) = @_;
18             my $self = $class->SUPER::new( $parent, -1 );
19              
20             $self->wxebug( $wxebug );
21             $self->{input} = Wx::TextCtrl->new( $self, -1, "", [-1,-1], [-1,-1],
22             wxTE_MULTILINE );
23             $self->{display} = Wx::TextCtrl->new( $self, -1, "", [-1,-1], [-1, -1],
24             wxTE_MULTILINE );
25             $self->{display_mode} = Wx::Choice->new( $self, -1 );
26              
27             $self->display_mode->Append( @$_ )
28             foreach [ 'YAML', 'use YAML; Dump(%s)' ],
29             [ 'Data::Dumper', 'use Data::Dumper; Dumper(%s)' ],
30             [ 'Plain', '%s' ];
31             $self->display_mode->SetSelection( 0 ); # FIXME save last
32             my $eval = Wx::Button->new( $self, -1, 'Eval' );
33             my $clear_eval = Wx::Button->new( $self, -1, 'Clear eval' );
34             my $clear_result = Wx::Button->new( $self, -1, 'Clear result' );
35              
36             my $sz = Wx::BoxSizer->new( wxVERTICAL );
37             my $b = Wx::BoxSizer->new( wxHORIZONTAL );
38             $sz->Add( $self->input, 1, wxGROW );
39             $sz->Add( $self->display, 1, wxGROW );
40             $b->Add( $eval, 0, wxALL, 2 );
41             $b->Add( $clear_eval, 0, wxALL, 2 );
42             $b->Add( $clear_result, 0, wxALL, 2 );
43             $b->Add( $self->display_mode, 1, wxALL, 2 );
44             $sz->Add( $b, 0, wxGROW );
45             $self->SetSizer( $sz );
46              
47             $self->set_layout_state( $layout_state ) if $layout_state;
48             $self->register_view;
49              
50             EVT_BUTTON( $self, $eval, sub { $self->_eval } );
51             EVT_BUTTON( $self, $clear_eval, sub { $self->input->Clear } );
52             EVT_BUTTON( $self, $clear_result, sub { $self->display->Clear } );
53              
54             $self->SetSize( $self->default_size );
55              
56             $self->register_configurable;
57             $self->apply_configuration( $self->get_configuration
58             ( $self->wxebug->service_manager ) );
59              
60             return $self;
61             }
62              
63             sub _eval {
64             my( $self ) = @_;
65              
66             my $mode = $self->display_mode->GetClientData
67             ( $self->display_mode->GetSelection );
68             my $expr = $self->input->GetValue;
69             my $v = $self->ebug->eval( sprintf $mode, $expr ) || "";
70             $self->display->WriteText( $v );
71             }
72              
73             sub configuration : Configurable {
74             my( $class ) = @_;
75              
76             return { configurable => __PACKAGE__,
77             configurator => 'configuration_simple',
78             };
79             }
80              
81             sub get_configuration_keys {
82             my( $class ) = @_;
83              
84             return { label => 'Eval view',
85             section => 'eval_view',
86             keys => [ { key => 'font',
87             type => 'font',
88             label => 'Font',
89             },
90             ],
91             };
92             }
93              
94             sub apply_configuration {
95             my( $self, $data ) = @_;
96              
97             if( $data->{keys}[0]{value} ) {
98             my $font = Wx::Font->new( $data->{keys}[0]{value} );
99             $self->input->SetFont( $font );
100             $self->display->SetFont( $font );
101             }
102             }
103              
104             1;