-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dist.pm
107 lines (84 loc) · 2.29 KB
/
Dist.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package CPAN::Forum::RM::Dist;
use strict;
use warnings;
our $VERSION = '0.20';
use CPAN::Forum::DB::Groups;
use CPAN::Forum::DB::Tags;
=head2 dist
List last few posts belonging to this group, provides a link to post a new
message within this group
/dist/XYZ
=cut
sub dist {
my ($self) = @_;
my $q = $self->query;
my $group_name = ${ $self->param("path_parameters") }[0] || '';
if ( $group_name =~ /^([\w-]+)$/ ) {
$group_name = $1;
} else {
return $self->internal_error(
"Probably bad regex when checking group name for '$group_name'",
);
}
my %params = (
hide_group => 1,
group => $group_name,
title => "CPAN Forum - $group_name",
);
my $gr = CPAN::Forum::DB::Groups->info_by( name => $group_name );
if ( not $gr ) {
$self->log->warning("Invalid group '$group_name'");
return $self->internal_error(
"",
"no_such_group",
);
}
my $gid = $gr->{id};
if ( $gid =~ /^(\d+)$/ ) {
$gid = $1;
} else {
return $self->internal_error(
"Invalid gid received '$gid'",
);
}
my $more_params = $self->set_ratings( $gr );
%params = (%params, %$more_params);
my $page = $q->param('page') || 1;
my $results = $self->_search_results( { where => { gid => $gid }, page => $page } );
if ($results) {
%params = (%params, %$results);
}
my $mp = $self->_subscriptions( $gr );
%params = (%params, %$mp);
# TODO: is is not clear to me how can here anything be undef, but I got
# several exceptions on eith $gr or $gr->pauseid being undef:
if ( $gr and $gr->{pauseid_name} ) {
$params{pauseid_name} = $gr->{pauseid_name};
}
my $frequent_tags = CPAN::Forum::DB::Tags->get_tags_of_module($gid);
$params{frequent_tags} = $frequent_tags;
my $uid = $self->session->param('uid');
if ($uid) {
my $mytags = CPAN::Forum::DB::Tags->get_tags_of( $gid, $uid );
$params{mytags} = $mytags;
$params{show_tags} = 1;
}
$params{group_id} = $gid;
return $self->tt_process('pages/dists.tt', \%params);
}
sub set_ratings {
my ( $self, $gr ) = @_;
my ( $rating, $review_count ) = ($gr->{rating}, $gr->{review_count});
if ( not $rating ) {
$rating = "0.0";
$review_count = 0;
}
return {} if not $rating; # ????
my $roundrating = sprintf "%1.1f", int( $rating * 2 ) / 2;
return {
rating => $rating,
roundrating => $roundrating,
review_count => $review_count,
}
}
1;