App/Chart/Weblink.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 76 CC 3 SCAR 13.9
CC
3
Cov
0%
new
12.0
links_for_symbol
2.0
url
2.0
CRAP 4.0
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::Weblink;
18 use 5.006;
19 use strict;
20 use warnings;
21 use Carp;
22 # use Locale::TextDomain ('App-Chart');
23  
24 use App::Chart;
25  
26 # uncomment this to run the ### lines
27 #use Smart::Comments;
28  
29 our @weblinks_list = ();
30  
31 sub new {
32 my ($class, %self) = @_;
33 my $self = bless \%self, $class;
34 require App::Chart::Sympred;
35 App::Chart::Sympred::validate ($self->{'pred'});
36 if (! ($self->{'url'} || $self->{'proc'})) {
37 croak "Missing weblink url or proc\n";
38 }
39 if (! $self->{'name'}) {
40 croak "Missing weblink name";
41 }
42  
43 push @weblinks_list, $self;
44 @weblinks_list = sort { $a->{'name'} cmp $b->{'name'} } @weblinks_list;
45 return $self;
46 }
47  
48 sub links_for_symbol {
49 my ($class, $symbol) = @_;
50 App::Chart::symbol_setups ($symbol);
51 return grep { $_->{'pred'}->match($symbol) } @weblinks_list;
52 }
53  
54 sub url {
55 my ($self, $symbol) = @_;
56 return $self->{'url'}
57 || $self->{'proc'}->($symbol);
58 }
59  
60 sub name {
61 my ($self) = @_;
62 return $self->{'name'};
63 }
64  
65 sub sensitive {
66 my ($self, $symbol) = @_;
67 # But should check without any downloading ...
68 return scalar ($self->url ($symbol));
69 }
70  
71 sub open {
72 my ($self, $symbol, $parent) = @_;
73 my $url = $self->url($symbol);
74 require App::Chart::Gtk2::GUI;
75 App::Chart::Gtk2::GUI::browser_open ($url, $parent);
76 }
77  
78 1;
79 __END__
80  
81 =for stopwords weblink weblinks Eg url ie
82  
83 =head1 NAME
84  
85 App::Chart::Weblink -- web page links for symbols
86  
87 =head1 SYNOPSIS
88  
89 use App::Chart::Weblink;
90  
91 =head1 DESCRIPTION
92  
93 A weblink is a URL to some web site page related to a symbol, such as a
94 company information page or commodity contract specifications. The weblinks
95 for a given symbol are presented under the "View/Web" menu in the main Chart
96 GUI.
97  
98 =head1 FUNCTIONS
99  
100 =over 4
101  
102 =item App::Chart::Weblink->new (name=>..., pred=>...)
103  
104 Create and register a new weblink. The return is a new
105 C<App::Chart::Weblink> object, though usually this is not of interest (only
106 all the links later with C<links_for_symbol> below).
107  
108 =item @list = App::Chart::Weblink->links_for_symbol ($symbol)
109  
110 Return a list of C<App::Chart::Weblink> objects for use on the given symbol.
111 Eg.
112  
113 my @links = App::Chart::Weblink->links_for_symbol ('BHP.AX');
114  
115 =back
116  
117 =head1 METHODS
118  
119 =over 4
120  
121 =item C<< $string = $weblink->name >>
122  
123 Return the menu item name for C<$weblink>. This can include a "_"
124 underscore for a mnemonic.
125  
126 =item C<< $string = $weblink->url ($symbol) >>
127  
128 Return the url for C<$weblink> on C<$symbol>.
129  
130 =item C<< $bool = $weblink->sensitive ($symbol) >>
131  
132 Return true if the menu item for C<$weblink> should be sensitive for
133 C<$symbol>, ie. there's a target URL for that symbol.
134  
135 =item C<< $weblink->open ($symbol) >>
136  
137 Open a web browser to show C<$weblink> for C<$symbol>.
138  
139 =back
140  
141 =head1 SEE ALSO
142  
143 L<App::Chart::Weblink::SandP>, L<App::Chart::Gtk2::WeblinkMenu>
144  
145 =cut