AnnoCPAN
view release on metacpan or search on metacpan
lib/AnnoCPAN/DBI.pm view on Meta::CPAN
type
=cut
package AnnoCPAN::DBI::Section;
use base 'AnnoCPAN::DBI';
use AnnoCPAN::PodToHtml;
use AnnoCPAN::PodParser ':all';
__PACKAGE__->table('section');
__PACKAGE__->columns(Essential => qw(id podver pos content type));
__PACKAGE__->has_a(podver => 'AnnoCPAN::DBI::PodVer');
__PACKAGE__->add_trigger(before_delete => \&before_delete);
my %methods = (
VERBATIM, 'verbatim',
TEXTBLOCK, 'textblock',
COMMAND, 'command',
);
sub html {
my ($self) = @_;
$self->{parser} ||= AnnoCPAN::PodToHtml->new;
my $method = $methods{$self->type};
my @args = $self->content;
if ($method eq 'command') {
# split into command and content
@args = $args[0] =~ /==?(\S+)\s+(.*)/s;
}
my $html = $self->{parser}->$method(@args);
}
sub before_delete {
my ($self) = @_;
# make sure no notes use us as their reference section...
for my $note ($self->original_notes) {
my $max_sim = 0;
my $best_sect;
for my $notepos ($note->notepos) {
if ($notepos->section->id != $self->id
and $notepos->score > $max_sim)
{
$max_sim = $notepos->score;
$best_sect = $notepos->section;
}
}
$note->section($best_sect);
$note->update;
}
}
=head2 AnnoCPAN::DBI::User
Represents an AnnoCPAN user. Columns:
id
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
( run in 1.632 second using v1.01-cache-2.11-cpan-97f6503c9c8 )