CGI-Application-NetNewsIface
view release on metacpan or search on metacpan
lib/CGI/Application/NetNewsIface.pm view on Meta::CPAN
map
{$self->_thread_render_node($_, $current) }
@{$node->{subs}}
) .
"</ul>") :
""
) .
"</li>";
}
# TODO :
# 2. Make the current article non-linked and bold.
# 3. Add the date (?).
sub _get_thread
{
my ($self, $nntp) = @_;
my $article = $self->param('article');
my $cache = CGI::Application::NetNewsIface::Cache::DBI->new(
{
'nntp' => $nntp,
'dsn' => $self->param('dsn'),
},
);
$cache->select($self->param('group'));
my ($thread, $coords) = $cache->get_thread($article);
return "<ul>" . $self->_thread_render_node($thread, $article) . "</ul>";
}
sub _css
{
my $self = shift;
$self->header_props(-type => 'text/css');
return <<"EOF";
.articles th, .articles td
{
vertical-align:top;
text-align: left;
}
.articles
{
border-collapse: collapse;
}
.articles td, .articles th
{
border: 1.5pt black solid;
padding: 2pt;
}
EOF
}
=head2 $cgiapp->update_group($group)
Updates the cache records for the NNTP group C<$group>. This method is used
for maintenance, to make sure a script loads promptly.
=cut
sub update_group
{
my $self = shift;
my $group = shift;
my $cache = CGI::Application::NetNewsIface::Cache::DBI->new(
{
'nntp' => $self->_get_nntp(),
'dsn' => $self->param('dsn'),
},
);
$cache->select($group);
}
=head2 $cgiapp->init_cache__sqlite()
Initializes the SQLite cache that is pointed by the DBI DSN given as
a parameter to the CGI script. This should be called before any use of the
CGI Application itself, because otherwise there will be no tables to operate
on.
=cut
sub init_cache__sqlite
{
my $self = shift;
return $self->_init_cache({'auto_inc' => "PRIMARY KEY AUTOINCREMENT"});
}
=head2 $cgiapp->init_cache__mysql()
Initializes the MySQL cache that is pointed by the DBI DSN given as
a parameter to the CGI script. This should be called before any use of the
CGI Application itself, because otherwise there will be no tables to operate
on.
=cut
sub init_cache__mysql
{
my $self = shift;
return $self->_init_cache({'auto_inc' => "PRIMARY KEY NOT NULL AUTO_INCREMENT"});
}
sub _init_cache
{
my $self = shift;
my $args = shift;
my $auto_inc = $args->{'auto_inc'};
require DBI;
my $dbh = DBI->connect($self->param('dsn'), "", "");
$dbh->do("CREATE TABLE groups (name varchar(255), idx INTEGER $auto_inc, last_art INTEGER)");
$dbh->do("CREATE TABLE articles (group_idx INTEGER, article_idx INTEGER, msg_id varchar(255), parent INTEGER, subject varchar(255), frm varchar(255), date varchar(255))");
$dbh->do("CREATE UNIQUE INDEX idx_groups_name ON groups (name)");
$dbh->do("CREATE UNIQUE INDEX idx_articles_primary ON articles (group_idx, article_idx)");
$dbh->do("CREATE INDEX idx_articles_msg_id ON articles (group_idx, msg_id)");
$dbh->do("CREATE INDEX idx_articles_parent ON articles (group_idx, parent)");
}
( run in 0.754 second using v1.01-cache-2.11-cpan-d7f47b0818f )