App/Chart/Gtk2/RawInfo.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 81 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__
88  
89 =for stopwords RawInfo
90  
91 =head1 NAME
92  
93 App::Chart::Gtk2::RawInfo -- raw symbol info display widget
94  
95 =head1 SYNOPSIS
96  
97 use App::Chart::Gtk2::RawInfo;
98 my $raw = App::Chart::Gtk2::RawInfo->new (symbol => 'FOO');
99  
100 =head1 WIDGET HIERARCHY
101  
102 C<App::Chart::Gtk2::RawInfo> is a subclass of C<Gtk2::Label>.
103  
104 Gtk2::Widget
105 Gtk2::Misc
106 Gtk2::Label
107 App::Chart::Gtk2::RawInfo
108  
109 =head1 DESCRIPTION
110  
111 A C<App::Chart::Gtk2::RawInfo> widget displays a raw info record for a given
112 symbol. It updates with new info records.
113  
114 =head1 FUNCTIONS
115  
116 =over 4
117  
118 =item C<< App::Chart::Gtk2::RawInfo->new (key=>value,...) >>
119  
120 Create and return a new RawInfo widget.
121  
122 =back
123  
124 =head1 PROPERTIES
125  
126 =over 4
127  
128 =item C<symbol> (string, default none)
129  
130 The stock symbol whose info record to display.
131  
132 =back
133  
134 =head1 SEE ALSO
135  
136 L<App::Chart::Gtk2::RawDialog>
137  
138 =cut