App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/Weblink.pm view on Meta::CPAN
# Copyright 2007, 2008, 2009, 2010, 2011 Kevin Ryde
# This file is part of Chart.
#
# Chart is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3, or (at your option) any later version.
#
# Chart is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with Chart. If not, see <http://www.gnu.org/licenses/>.
package App::Chart::Weblink;
use 5.006;
use strict;
use warnings;
use Carp;
# use Locale::TextDomain ('App-Chart');
use App::Chart;
# uncomment this to run the ### lines
#use Smart::Comments;
our @weblinks_list = ();
sub new {
my ($class, %self) = @_;
my $self = bless \%self, $class;
require App::Chart::Sympred;
App::Chart::Sympred::validate ($self->{'pred'});
if (! ($self->{'url'} || $self->{'proc'})) {
croak "Missing weblink url or proc\n";
}
if (! $self->{'name'}) {
croak "Missing weblink name";
}
push @weblinks_list, $self;
@weblinks_list = sort { $a->{'name'} cmp $b->{'name'} } @weblinks_list;
return $self;
}
sub links_for_symbol {
my ($class, $symbol) = @_;
App::Chart::symbol_setups ($symbol);
return grep { $_->{'pred'}->match($symbol) } @weblinks_list;
}
sub url {
my ($self, $symbol) = @_;
return $self->{'url'}
|| $self->{'proc'}->($symbol);
}
sub name {
my ($self) = @_;
return $self->{'name'};
}
sub sensitive {
my ($self, $symbol) = @_;
# But should check without any downloading ...
return scalar ($self->url ($symbol));
}
sub open {
my ($self, $symbol, $parent) = @_;
my $url = $self->url($symbol);
require App::Chart::Gtk2::GUI;
App::Chart::Gtk2::GUI::browser_open ($url, $parent);
}
1;
__END__
=for stopwords weblink weblinks Eg url ie
=head1 NAME
App::Chart::Weblink -- web page links for symbols
=head1 SYNOPSIS
use App::Chart::Weblink;
=head1 DESCRIPTION
A weblink is a URL to some web site page related to a symbol, such as a
company information page or commodity contract specifications. The weblinks
for a given symbol are presented under the "View/Web" menu in the main Chart
( run in 0.945 second using v1.01-cache-2.11-cpan-39bf76dae61 )