AnnoCPAN
view release on metacpan or search on metacpan
lib/AnnoCPAN/DBI.pm view on Meta::CPAN
username
password
name
email
profile
reputation
member_since
last_visit
privs
Note that some of these columns are unused, but they exist for historical
reasons.
Other Methods:
=over
=cut
package AnnoCPAN::DBI::User;
use base 'AnnoCPAN::DBI';
__PACKAGE__->table('user');
__PACKAGE__->columns(Essential => qw(id username password name email profile
reputation member_since last_visit privs));
=item $user->can_delete($note)
Return true if the user has the authority to delete $note (an
AnnoCPAN::DBI::Note object).
=cut
sub can_delete {
my ($user, $note) = @_;
($user->privs > 1 or $user == $note->user);
}
=item $user->can_edit($note)
Return true if the user has the authority to edit $note (an
AnnoCPAN::DBI::Note object).
=cut
sub can_edit { shift->can_delete(@_) }
=item $user->can_move($note)
Return true if the user has the authority to move $note (an
AnnoCPAN::DBI::Note object).
=back
=cut
sub can_move { shift->can_delete(@_) }
sub can_hide { shift->can_delete(@_) }
package AnnoCPAN::DBI::Prefs;
use base 'AnnoCPAN::DBI';
__PACKAGE__->table('prefs');
__PACKAGE__->columns(Essential => qw(id user name value));
__PACKAGE__->has_a(user => 'AnnoCPAN::DBI::User');
package AnnoCPAN::DBI::Vote;
use base 'AnnoCPAN::DBI';
__PACKAGE__->table('vote');
__PACKAGE__->columns(Essential => qw(id note user value));
=head2 AnnoCPAN::DBI::Note
Represents a note. Columns:
id
pod
min_ver
max_ver
note
ip
time
score
user
section
Note that some of these columns are unused, but they exist for historical
reasons.
=cut
package AnnoCPAN::DBI::Note;
use base 'AnnoCPAN::DBI';
use String::Similarity 'similarity';
use AnnoCPAN::PodParser ':all';
use POSIX qw(nice);
use constant {
ORIGINAL => 1,
MOVED => 2,
CALCULATED => 0,
HIDDEN => -1,
SCALE => 1000,
};
my $recent_notes = AnnoCPAN::Config->option('recent_notes') || 25;
__PACKAGE__->table('note');
__PACKAGE__->columns(
Essential => qw(id pod min_ver max_ver note ip time score user section));
sub recent {
my ($self, $start, $count) = @_;
$start ||= 0;
$count ||= $recent_notes;
return $self->retrieve_from_sql(
"1 ORDER BY time DESC LIMIT $start, $count");
}
__PACKAGE__->set_sql(recent_by_author => "SELECT DISTINCT n.id
FROM note n, distver dv, podver pv, pod p
WHERE dv.pause_id=? AND pv.distver=dv.id AND pv.pod=p.id
AND n.pod=p.id
lib/AnnoCPAN/DBI.pm view on Meta::CPAN
sub is_visible {
my ($self) = @_;
($self->status != AnnoCPAN::DBI::Note::HIDDEN);
}
sub hide {
my ($self) = @_;
return unless $self->is_visible;
$self->status(AnnoCPAN::DBI::Note::HIDDEN);
$self->update;
$self->podver->html('');
$self->podver->update;
}
sub unhide {
my ($self) = @_;
return if $self->is_visible;
$self->status(AnnoCPAN::DBI::Note::MOVED);
$self->update;
$self->podver->html('');
$self->podver->update;
}
sub score_class {
my ($self) = @_;
my $score = $self->score;
"sim_" . int($score / 100) * 10;
}
sub time { shift->note->time }
sub distver_mtime { shift->section->podver->mtime }
sub podver { shift->section->podver }
__PACKAGE__->set_sql(
podver_note => "SELECT notepos.id FROM notepos, section
WHERE notepos.section=section.id AND section.podver=?
AND notepos.note=?");
__PACKAGE__->set_sql(
by_podver => 'SELECT np.id FROM notepos np, section s, podver pv, note n
WHERE s.podver = pv.id AND np.section = s.id AND np.note = n.id
AND pv.id=?
ORDER BY np.section, n.time');
package AnnoCPAN::DBI::Author;
use base 'AnnoCPAN::DBI';
__PACKAGE__->table('author');
__PACKAGE__->columns(Essential => qw(id pause_id name email url));
# ONE TO MANY
AnnoCPAN::DBI::Dist->has_many(distvers => 'AnnoCPAN::DBI::DistVer',
{ order_by => 'mtime' });
AnnoCPAN::DBI::Pod->has_many(podvers => 'AnnoCPAN::DBI::PodVer');
AnnoCPAN::DBI::Pod->has_many(notes => 'AnnoCPAN::DBI::Note');
AnnoCPAN::DBI::Pod->has_many(pod_dists => 'AnnoCPAN::DBI::PodDist');
AnnoCPAN::DBI::PodVer->has_many(sections => 'AnnoCPAN::DBI::Section',
{ order_by => 'pos' } );
AnnoCPAN::DBI::DistVer->has_many(podvers => 'AnnoCPAN::DBI::PodVer');
AnnoCPAN::DBI::User->has_many(prefs => 'AnnoCPAN::DBI::Prefs');
AnnoCPAN::DBI::User->has_many(
notes => 'AnnoCPAN::DBI::Note', { order_by => 'time DESC' });
AnnoCPAN::DBI::Section->has_many(notepos => 'AnnoCPAN::DBI::NotePos');
AnnoCPAN::DBI::Section->has_many(original_notes => 'AnnoCPAN::DBI::Note');
AnnoCPAN::DBI::Note->has_many(notepos => 'AnnoCPAN::DBI::NotePos');
# MANY TO MANY
AnnoCPAN::DBI::Section->has_many(
notes => ['AnnoCPAN::DBI::NotePos' => 'note']);
AnnoCPAN::DBI::Note->has_many(
sections => ['AnnoCPAN::DBI::NotePos' => 'section']);
AnnoCPAN::DBI::Pod->has_many(
dists => ['AnnoCPAN::DBI::PodDist' => 'dist']);
AnnoCPAN::DBI::Dist->has_many(
pods => ['AnnoCPAN::DBI::PodDist' => 'pod']);
=head1 SEE ALSO
L<AnnoCPAN::Control>, L<AnnoCPAN::Config>
=head1 AUTHOR
Ivan Tubert-Brohman E<lt>itub@cpan.orgE<gt>
=head1 COPYRIGHT
Copyright (c) 2005 Ivan Tubert-Brohman. All rights reserved. This program is
free software; you can redistribute it and/or modify it under the same terms as
Perl itself.
=cut
1;
( run in 1.230 second using v1.01-cache-2.11-cpan-5a3173703d6 )