1 # This module is a plugin for WWW::Scraper, and allows one to search
2 # google, and is released under the terms of the GPL version 2, or any
3 # later version. See the file README and COPYING for more
4 # information. Copyright 2002 by Don Armstrong <don@donarmstrong.com>.
13 use vars qw($VERSION $DEBUG);
17 $VERSION = q($Rev: $);
23 my $ua = LWP::UserAgent->new;
24 $ua->agent("blootbug_debbugs/$VERSION");
27 my $req = HTTP::Request->new( GET => $url );
29 # Pass request to the user agent and get a response back
30 my $res = $ua->request($req);
32 # Check the outcome of the response
33 if ( $res->is_success ) {
43 my $options = shift || {};
45 if ( not $bug_num =~ /^\#?\d+$/ ) {
46 warn "Bug is not a number!" and return undef
47 if not $options->{return_warnings};
48 return "Bug is not a number!";
52 get_url("http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=$bug_num");
54 # strip down report to relevant header information.
55 $report =~ /<HEAD>(.+?)<HR>/s;
58 ( $bug->{num}, $bug->{title} ) =
59 $report =~ m#\#(\d+)\<\/A\>\<BR\>(.+?)\<\/H1\>#is;
61 print "Bugnum: $bug->{num}\nTitle: $bug->{title}\nReport: $report\n";
63 $bug->{title} =~ s/</\</g;
64 $bug->{title} =~ s/>/\>/g;
65 $bug->{title} =~ s/"/\"/g;
66 $bug->{severity} = 'n'; #Default severity is normal
67 my @bug_flags = split /(?<!\&.t)[;\.]\n/s, $report;
68 foreach my $bug_flag (@bug_flags) {
69 print "Bug_flag: $bug_flag\n" if $DEBUG;
70 if ( $bug_flag =~ /Severity:/i ) {
71 ( $bug->{severity} ) =
72 $bug_flag =~ /(wishlist|minor|normal|important|serious|grave)/i;
74 # Just leave the leter instead of the whole thing.
75 $bug->{severity} =~ s/^(.).+$/$1/;
77 elsif ( $bug_flag =~ /Package:/ ) {
78 ( $bug->{package} ) = $bug_flag =~ /\"\>\s*([^\<\>\"]+?)\s*\<\/a\>/;
80 elsif ( $bug_flag =~ /Reported by:/ ) {
81 ( $bug->{reporter} ) = $bug_flag =~ /\"\>\s*(.+?)\s*\<\/a\>/;
84 $bug->{reporter} =~ s/</\</g;
85 $bug->{reporter} =~ s/>/\>/g;
87 elsif ( $bug_flag =~ /Date:/ ) {
88 ( $bug->{date} ) = $bug_flag =~ /Date:\s*(\w.+?)\s*$/;
90 #ditch extra whitespace
91 $bug->{date} =~ s/\s{2,}/\ /;
93 elsif ( $bug_flag =~ /Tags:/ ) {
94 ( $bug->{tags} ) = $bug_flag =~ /strong\>\s*(.+?)\s*\<\/strong\>/;
96 elsif ( $bug_flag =~ /merged with / ) {
97 $bug_flag =~ s/merged with\s*//;
98 $bug_flag =~ s/\<[^\>]+\>//g;
99 $bug_flag =~ s/\s//sg;
100 $bug->{merged_with} = $bug_flag;
103 elsif ( $bug_flag =~ /\>Done:\</ ) {
106 elsif ( $bug_flag =~ /\>Fixed\</ ) {
114 $report .= 'DONE:' if defined $bug->{done} and $bug->{done};
117 . uc( $bug->{severity} ) . '['
118 . $bug->{package} . '] '
120 $report .= ' (' . $bug->{tags} . ')' if defined $bug->{tags};
121 $report .= '; ' . $bug->{date};
123 # Avoid reporting so many merged bugs.
125 . join( ',', splice( @{ [ split( /,/, $bug->{merged_with} ) ] }, 0, 3 ) )
127 if defined $bug->{merged_with};
130 print STDERR Dumper($bug);
135 sub package_bugs($) {
144 # vim:ts=4:sw=4:expandtab:tw=80