]> git.deb.at Git - deb/packages.git/blob - lib/Parse/DebianChangelog/ChangesFilters.pm
Parse::DebianChangelog: update to 1.1.1
[deb/packages.git] / lib / Parse / DebianChangelog / ChangesFilters.pm
1 #
2 # Parse::DebianChangelog::ChangesFilters
3 #
4 # Copyright 2005 Frank Lichtenheld <frank@lichtenheld.de>
5 #
6 #    This program is free software; you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License as published by
8 #    the Free Software Foundation; either version 2 of the License, or
9 #    (at your option) any later version.
10 #
11 #    This program is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with this program; if not, write to the Free Software
18 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19 #
20
21 =head1 NAME
22
23 Parse::DebianChangelog::ChangesFilters - filters to be applied to Debian changelog entries
24
25 =head1 SYNOPSIS
26
27 =head1 DESCRIPTION
28
29 This is currently only used internally by Parse::DebianChangelog and
30 is not yet documented. There may be still API changes until this module
31 is finalized.
32
33 =cut
34
35 package Parse::DebianChangelog::ChangesFilters;
36
37 our @ISA = qw(Exporter);
38
39 our %EXPORT_TAGS = ( 'all' => [ qw(
40                                    encode_entities
41                                    http_ftp_urls
42                                    email_to_ddpo
43                                    bugs_to_bts
44                                    cve_to_mitre
45                                    pseudo_markup
46                                    common_licenses
47 ) ] );
48
49 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
50
51 our @all_filters = (
52                     \&encode_entities,
53                     \&http_ftp_urls,
54                     \&email_to_ddpo,
55                     \&bugs_to_bts,
56                     \&cve_to_mitre,
57                     \&pseudo_markup,
58                     \&common_licenses,
59                     );
60
61 sub encode_entities {
62     require HTML::Entities;
63
64     return HTML::Entities::encode_entities( "$_[0]", '<>&"' ) || '';
65 }
66
67 sub http_ftp_urls {
68     my ($text, $cgi) = @_;
69
70     $text=~ s|&lt;URL:([-\w\.\/:~_\@]+):([a-zA-Z0-9\'() ]+)&gt;
71         |$cgi->a({ -href=>$1 }, $2)
72         |xego;
73     $text=~ s|https?:[\w/\.:\@+\-~\%\#?=&;,]+[\w/]
74         |$cgi->a({ -href=>$& }, $&)
75         |xego;
76     $text=~ s|ftp:[\w/\.:\@+\-~\%\#?=&;,]+[\w/]
77         |$cgi->a({ -href=>$& }, $&)
78         |xego;
79
80     return $text;
81 }
82
83 sub email_to_ddpo {
84     my ($text, $cgi) = @_;
85
86     $text =~ s|[a-zA-Z0-9_\+\-\.]+\@([a-zA-Z0-9][\w\.+\-]+\.[a-zA-Z]{2,})
87         |$cgi->a({ -href=>"http://qa.debian.org/developer.php?login=$&" }, $&)
88         |xego;
89     return $text;
90 }
91
92 sub bugs_to_bts {
93     (my $text = $_[0]) =~ s|Closes:\s*(?:Bug)?\#\d+(?:\s*,\s*(?:Bug)?\#\d+)*
94         |my $tmp = $&; { no warnings;
95                          $tmp =~ s@(Bug)?\#(\d+)@<a class="buglink" href="http://bugs.debian.org/$2">$1\#$2</a>@ig; }
96     "$tmp"
97         |xiego;
98     return $text;
99 }
100
101 sub cve_to_mitre {
102     my ($text, $cgi) = @_;
103
104     $text =~ s!\b(?:CVE|CAN)-\d{4}-\d{4}\b
105         !$cgi->a({ -href=>"http://cve.mitre.org/cgi-bin/cvename.cgi?name=$&" }, $&)
106         !xego;
107     return $text;
108 }
109
110 sub pseudo_markup {
111     my ($text, $cgi) = @_;
112
113     $text =~ s|\B\*([a-z][a-z -]*[a-z])\*\B
114         |$cgi->em($1)
115         |xiego;
116     $text=~ s|\B\*([a-z])\*\B
117         |$cgi->em($1)
118         |xiego;
119     $text=~ s|\B\#([a-z][a-z -]*[a-z])\#\B
120         |$cgi->strong($1)
121         |xego;
122     $text=~ s|\B\#([a-z])\#\B
123         |$cgi->strong($1)
124         |xego;
125
126     return $text;
127 }
128
129 sub common_licenses {
130     my ($text, $cgi) = @_;
131
132     $text=~ s|/usr/share/common-licenses/GPL(?:-2)?
133         |$cgi->a({ -href=>"http://www.gnu.org/copyleft/gpl.html" }, $&)
134         |xego;
135     $text=~ s|/usr/share/common-licenses/LGPL(?:-2(?:\.1)?)?
136         |$cgi->a({ -href=>"http://www.gnu.org/copyleft/lgpl.html" }, $&)
137         |xego;
138     $text=~ s|/usr/share/common-licenses/Artistic
139         |$cgi->a({ -href=>"http://www.opensource.org/licenses/artistic-license.php" }, $&)
140         |xego;
141     $text=~ s|/usr/share/common-licenses/BSD
142         |$cgi->a({ -href=>"http://www.debian.org/misc/bsd.license" }, $&)
143         |xego;
144
145     return $text;
146 }
147
148 sub all_filters {
149     my ($text, $cgi) = @_;
150
151     $text = encode_entities( $text, $cgi );
152     $text = http_ftp_urls( $text, $cgi );
153     $text = email_to_ddpo( $text, $cgi );
154     $text = bugs_to_bts( $text, $cgi );
155     $text = cve_to_mitre( $text, $cgi );
156     $text = pseudo_markup( $text, $cgi );
157     $text = common_licenses( $text, $cgi );
158
159     return $text;
160 }
161
162 1;
163 __END__
164
165 =head1 SEE ALSO
166
167 Parse::DebianChangelog
168
169 =head1 AUTHOR
170
171 Frank Lichtenheld, E<lt>frank@lichtenheld.deE<gt>
172
173 =head1 COPYRIGHT AND LICENSE
174
175 Copyright (C) 2005 by Frank Lichtenheld
176
177 This program is free software; you can redistribute it and/or modify
178 it under the terms of the GNU General Public License as published by
179 the Free Software Foundation; either version 2 of the License, or
180 (at your option) any later version.
181
182 This program is distributed in the hope that it will be useful,
183 but WITHOUT ANY WARRANTY; without even the implied warranty of
184 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
185 GNU General Public License for more details.
186
187 You should have received a copy of the GNU General Public License
188 along with this program; if not, write to the Free Software
189 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
190
191 =cut