App/Chart/Gtk2/RawInfo.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 82 CC 4 SCAR 12.5
CC
4
Cov
0%
SET_PROPERTY
6.0
_do_data_changed
6.0
refresh
6.0
CRAP 3.5
1 # Copyright 2007, 2008, 2009, 2010, 2011 Kevin Ryde
2  
3 # This file is part of Chart.
4 #
5 # Chart is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3, or (at your option) any later version.
8 #
9 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Chart. If not, see <http://www.gnu.org/licenses/>.
16  
17 package App::Chart::Gtk2::RawInfo;
18 use 5.010;
19 use strict;
20 use warnings;
21 use Gtk2;
22 use List::Util;
23 use Locale::TextDomain ('App-Chart');
24  
25 # uncomment this to run the ### lines
26 #use Smart::Comments;
27  
28 use Glib::Object::Subclass
29 'Gtk2::Label',
30 properties => [Glib::ParamSpec->string
31 ('symbol',
32 __('Symbol'),
33 'Blurb.',
34 '',
35 Glib::G_PARAM_READWRITE),
36 ];
37  
38  
39 sub INIT_INSTANCE {
40 my ($self) = @_;
41 $self->set_alignment (0, 0);
42 App::Chart::chart_dirbroadcast()->connect_for_object
43 ('data-changed', \&_do_data_changed, $self);
44 }
45  
46 sub SET_PROPERTY {
47 my ($self, $pspec, $newval) = @_;
48 my $pname = $pspec->get_name;
49 ### RawInfo: $pname, $newval
50 $self->{$pname} = $newval; # per default GET_PROPERTY
51  
52 if ($pname eq 'symbol') {
53 $self->refresh;
54 }
55 }
56  
57 # 'data-changed' handler
58 sub _do_data_changed {
59 my ($self, $symbol_hash) = @_;
60 my $symbol = $self->{'symbol'} // return;
61 if (exists $symbol_hash->{$symbol}) {
62 $self->refresh;
63 }
64 }
65  
66 sub refresh {
67 my ($self) = @_;
68 my $symbol = $self->{'symbol'};
69 my $str;
70 if (defined $symbol) {
71 ### RawInfo refresh: $symbol
72 require App::Chart::DBI;
73 my $dbh = App::Chart::DBI->instance;
74 my $sth = $dbh->prepare_cached ('SELECT * FROM info WHERE symbol=?');
75 my $h = $dbh->selectrow_hashref ($sth, undef, $symbol);
76  
77 require Data::Dumper;
78 my $dumper = Data::Dumper->new ([$h],['info']);
79 $dumper->Sortkeys(1);
80 $dumper->Quotekeys(0);
81 $str = $dumper->Dump;
82 }
83 $self->set_text ($str);
84 }
85  
86 1;
87 __END__