r47885 - /trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff
azatoth-guest at users.alioth.debian.org
azatoth-guest at users.alioth.debian.org
Sat Nov 28 22:29:41 UTC 2009
Author: azatoth-guest
Date: Sat Nov 28 22:29:36 2009
New Revision: 47885
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=47885
Log:
extend with own error "classes"
Modified:
trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff
Modified: trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff?rev=47885&op=diff
==============================================================================
--- trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff (original)
+++ trunk/libparse-debcontrol-perl/debian/patches/strict_parse.diff Sat Nov 28 22:29:36 2009
@@ -1,12 +1,12 @@
Index: libparse-debcontrol-perl/lib/Parse/DebControl.pm
===================================================================
---- libparse-debcontrol-perl.orig/lib/Parse/DebControl.pm 2009-11-28 18:20:31.000000000 +0100
-+++ libparse-debcontrol-perl/lib/Parse/DebControl.pm 2009-11-28 18:20:49.000000000 +0100
+--- libparse-debcontrol-perl.orig/lib/Parse/DebControl.pm 2009-11-28 23:27:32.000000000 +0100
++++ libparse-debcontrol-perl/lib/Parse/DebControl.pm 2009-11-28 23:27:44.000000000 +0100
@@ -13,10 +13,111 @@
use IO::Scalar;
use Compress::Zlib;
use LWP::UserAgent;
-+use Error;
++use Parse::DebControl::Error;
use vars qw($VERSION);
$VERSION = '2.005';
@@ -120,7 +120,7 @@
{
- $this->_dowarn("parse_file failed because no filename parameter was given");
- return;
-+ throw Error::Simple("parse_file failed because no filename parameter was given");
++ throw Parse::DebControl::Error::IO("parse_file failed because no filename parameter was given");
}
my $fh;
@@ -128,7 +128,7 @@
{
- $this->_dowarn("parse_file failed because $filename could not be opened for reading");
- return;
-+ throw Error::Simple("parse_file failed because $filename could not be opened for reading");
++ throw Parse::DebControl::Error::IO("parse_file failed because $filename could not be opened for reading");
}
return $this->_parseDataHandle($fh, $options);
@@ -138,7 +138,7 @@
{
- $this->_dowarn("parse_mem failed because no data was given");
- return;
-+ throw Error::Simple("parse_mem failed because no data was given");
++ throw Parse::DebControl::Error::IO("parse_mem failed because no data was given");
}
my $IOS = new IO::Scalar \$data;
@@ -147,7 +147,7 @@
{
- $this->_dowarn("parse_mem failed because IO::Scalar creation failed.");
- return;
-+ throw Error::Simple("parse_mem failed because IO::Scalar creation failed.");
++ throw Parse::DebControl::Error::IO("parse_mem failed because IO::Scalar creation failed.");
}
return $this->_parseDataHandle($IOS, $options);
@@ -157,7 +157,7 @@
{
- $this->_dowarn("No url given, thus no data to parse");
- return;
-+ throw Error::Simple("No url given, thus no data to parse");
++ throw Parse::DebControl::Error::IO("No url given, thus no data to parse");
}
my $ua = LWP::UserAgent->new;
@@ -167,7 +167,7 @@
{
- $this->_dowarn("Failed to instantiate HTTP Request object");
- return;
-+ throw Error::Simple("Failed to instantiate HTTP Request object");
++ throw Parse::DebControl::Error::IO("Failed to instantiate HTTP Request object");
}
my $response = $ua->request($request);
@@ -177,7 +177,7 @@
} else {
- $this->_dowarn("Failed to fetch $url from the web");
- return;
-+ throw Error::Simple("Failed to fetch $url from the web");
++ throw Parse::DebControl::Error::IO("Failed to fetch $url from the web");
}
}
@@ -187,14 +187,14 @@
{
- $this->_dowarn("write_file failed because no filename or filehandle was given");
- return;
-+ throw Error::Simple("write_file failed because no filename or filehandle was given");
++ throw Parse::DebControl::Error::IO("write_file failed because no filename or filehandle was given");
}
unless($dataorarrayref)
{
- $this->_dowarn("write_file failed because no data was given");
- return;
-+ throw Error::Simple("write_file failed because no data was given");
++ throw Parse::DebControl::Error::IO("write_file failed because no data was given");
}
my $handle = $this->_getValidHandle($filenameorhandle, $options);
@@ -203,7 +203,7 @@
{
- $this->_dowarn("write_file failed because we couldn't negotiate a valid handle");
- return;
-+ throw Error::Simple("write_file failed because we couldn't negotiate a valid handle");
++ throw Parse::DebControl::Error::IO("write_file failed because we couldn't negotiate a valid handle");
}
my $string = $this->write_mem($dataorarrayref, $options);
@@ -213,7 +213,7 @@
{
- $this->_dowarn("write_mem failed because no data was given");
- return;
-+ throw Error::Simple("write_mem failed because no data was given");
++ throw Parse::DebControl::Error::IO("write_mem failed because no data was given");
}
my $arrayref = $this->_makeArrayref($dataorarrayref);
@@ -223,7 +223,7 @@
{
- $this->_dowarn("Can't get a valid filehandle to write to, because that is closed");
- return;
-+ throw Error::Simple("Can't get a valid filehandle to write to, because that is closed");
++ throw Parse::DebControl::Error::IO("Can't get a valid filehandle to write to, because that is closed");
}
return $filenameorhandle;
@@ -233,7 +233,7 @@
{
- $this->_dowarn("Couldn't open file: $openmode$filenameorhandle for writing");
- return;
-+ throw Error::Simple("Couldn't open file: $openmode$filenameorhandle for writing");
++ throw Parse::DebControl::Error::IO("Couldn't open file: $openmode$filenameorhandle for writing");
}
return $handle;
@@ -243,7 +243,7 @@
{
- $this->_dowarn("_parseDataHandle failed because no handle was given. This is likely a bug in the module");
- return;
-+ throw Error::Simple("_parseDataHandle failed because no handle was given. This is likely a bug in the module");
++ throw Parse::DebControl::Error("_parseDataHandle failed because no handle was given. This is likely a bug in the module");
}
if($options->{tryGzip})
@@ -276,7 +276,7 @@
}else{
- $this->_dowarn("Parse error on line $linenum of data; invalid key/value stanza");
- return $structs;
-+ throw Error::Simple("Parse error on line $linenum of data; invalid key/value stanza");
++ throw Parse::DebControl::Error::Parse('invalid key/value stansa', $linenum, $line);
}
}elsif($line =~ /^([\t\s])(.*)/)
@@ -287,7 +287,7 @@
+
+ unless($lastfield)
+ {
-+ throw Error::Simple("Parse error on line $linenum of data; indented entry without previous line");
++ throw Parse::DebControl::Error::Parse('indented entry without previous line', $linenum, $line);
+ }
+ if( $options->{strict} ) {
+ if(
@@ -295,7 +295,7 @@
+ && exists $strict_single_line_fields->{$options->{type}}->{lc $lastfield}
+ && $strict_single_line_fields->{$options->{type}}->{lc $lastfield} == 1
+ ) {
-+ throw Error::Simple("Parse error on line $linenum of data; field $lastfield for type $options->{type} may not span multiple lines");
++ throw Parse::DebControl::Error::Parse("field $lastfield for type $options->{type} may not span multiple lines", $linenum);
+ }
+ }
@@ -336,7 +336,7 @@
+ && exists $strict_rules->{$options->{type}}->{lc $lastfield}
+ && $data->{$lastfield} !~ $strict_rules->{$options->{type}}->{lc $lastfield}
+ ) {
-+ throw Error::Simple("Parse error on line $linenum of data; field $lastfield for type $options->{type} doesn't match rule");
++ throw Parse::DebControl::Error::Parse("field $lastfield for type $options->{type} doesn't match rule", $linenum);
+ }
+
+ }
@@ -346,7 +346,7 @@
+ $data = $this->_getReadyHash($options);
+ $lastfield = "";
+ }else{
-+ throw Error::Simple("Parse error on line $linenum of data; unidentified line structure");
++ throw Parse::DebControl::Error::Parse("unidentified line structure", $linenum, $line);
+ }
}
@@ -357,7 +357,7 @@
{
- $this->_dowarn("Can't use Tie::IxHash. You need to install it to have this functionality");
- return;
-+ throw Error::Simple("Can't use Tie::IxHash. You need to install it to have this functionality");
++ throw Parse::DebControl::Error("Can't use Tie::IxHash. You need to install it to have this functionality");
}
tie(%$data, "Tie::IxHash");
return $data;
@@ -402,7 +402,7 @@
Index: libparse-debcontrol-perl/t/34strict.t
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ libparse-debcontrol-perl/t/34strict.t 2009-11-28 18:20:49.000000000 +0100
++++ libparse-debcontrol-perl/t/34strict.t 2009-11-28 23:27:44.000000000 +0100
@@ -0,0 +1,47 @@
+#
+#===============================================================================
@@ -450,11 +450,11 @@
+ "Source: foo\n#This is a comment\nPackage: bar\#another comment\n#thid comment\nPriority: required",
+ {strict => 1, type => 'DEBIAN/control'}
+ )
-+} 'Error::Simple', "Error thrown";
++} 'Parse::DebControl::Error::Parse', "Error thrown";
Index: libparse-debcontrol-perl/t/30parse.t
===================================================================
---- libparse-debcontrol-perl.orig/t/30parse.t 2009-11-28 18:20:31.000000000 +0100
-+++ libparse-debcontrol-perl/t/30parse.t 2009-11-28 18:20:49.000000000 +0100
+--- libparse-debcontrol-perl.orig/t/30parse.t 2009-11-28 23:27:32.000000000 +0100
++++ libparse-debcontrol-perl/t/30parse.t 2009-11-28 23:27:44.000000000 +0100
@@ -1,6 +1,7 @@
#!/usr/bin/perl -w
@@ -469,15 +469,15 @@
- ok(!$pdc->parse_mem(), "Parser should fail if not given a name");
- ok(!$pdc->parse_file(), "Parser should fail if not given a filename");
-+ throws_ok { $pdc->parse_mem() } 'Error::Simple', "Parser should fail if not given a name";
-+ throws_ok { $pdc->parse_file() } 'Error::Simple', "Parser should fail if not given a filename";
++ throws_ok { $pdc->parse_mem() } 'Parse::DebControl::Error::IO', "Parser should fail if not given a name";
++ throws_ok { $pdc->parse_file() } 'Parse::DebControl::Error::IO', "Parser should fail if not given a filename";
#Single item (no ending newline) parsing - 8 tests
Index: libparse-debcontrol-perl/t/40write.t
===================================================================
---- libparse-debcontrol-perl.orig/t/40write.t 2009-11-28 18:20:31.000000000 +0100
-+++ libparse-debcontrol-perl/t/40write.t 2009-11-28 18:23:45.000000000 +0100
+--- libparse-debcontrol-perl.orig/t/40write.t 2009-11-28 23:27:32.000000000 +0100
++++ libparse-debcontrol-perl/t/40write.t 2009-11-28 23:27:44.000000000 +0100
@@ -1,7 +1,8 @@
#!/usr/bin/perl -w
@@ -495,9 +495,9 @@
-ok(!$writer->write_mem(), "write_mem should fail without data");
-ok(!$writer->write_file(), "write_file should fail without a filename or handle");
-ok(!$writer->write_file('/fake/file'), "write_file should fail without data");
-+throws_ok { $writer->write_mem() } 'Error::Simple', "write_mem should fail without data";
-+throws_ok { $writer->write_file() } 'Error::Simple', "write_file should fail without a filename or handle";
-+throws_ok { $writer->write_file('/fake/file') } 'Error::Simple', "write_file should fail without data";
++throws_ok { $writer->write_mem() } 'Parse::DebControl::Error::IO', "write_mem should fail without data";
++throws_ok { $writer->write_file() } 'Parse::DebControl::Error::IO', "write_file should fail without a filename or handle";
++throws_ok { $writer->write_file('/fake/file') } 'Parse::DebControl::Error::IO', "write_file should fail without data";
ok($writer->write_mem({'foo' => 'bar'}) eq "foo: bar\n", "write_* should translate simple items correctly");
@@ -509,3 +509,83 @@
-$mem = $writer->write_mem();
-ok($warnings eq "", "Writing blank arrayrefs doesn't throw warnings"); #Version 1.9 fix
-
+Index: libparse-debcontrol-perl/lib/Parse/DebControl/Error.pm
+===================================================================
+--- /dev/null 1970-01-01 00:00:00.000000000 +0000
++++ libparse-debcontrol-perl/lib/Parse/DebControl/Error.pm 2009-11-28 23:28:10.000000000 +0100
+@@ -0,0 +1,75 @@
++use strict;
++use warnings;
++
++package Parse::DebControl::Error;
++use base 'Error';
++our $VERSION = '0.1';
++sub new
++{
++ my $self = shift;
++ local $Error::Depth = $Error::Depth + 1;
++
++ $self->SUPER::new(@_);
++}
++
++package Parse::DebControl::Error::Parse;
++use base 'Parse::DebControl::Error';
++our $VERSION = '0.1';
++
++sub new
++{
++ my $self = shift;
++ my $text = "".shift;
++ my @args = ();
++
++ my $line = shift;
++ my $context = shift;
++
++ push(@args, '-context', $context) if defined($context);
++ push(@args, '-line', $line) if defined($line);
++
++ local $Error::Depth = $Error::Depth + 1;
++
++ $self->SUPER::new(-text => $text, @args);
++}
++
++sub stringify {
++ my $self = shift;
++ my $text;
++ if( $self->context ) {
++ $text = sprintf("Parse error: %s at line %d of data (\"%s\").\n", $self->SUPER::stringify, $self->line, $self->context);
++ } elsif( $self->line ) {
++ $text = sprintf("Parse error: %s at line %d of data.\n", $self->SUPER::stringify, $self->line);
++ } else {
++ $text = sprintf("Parse error: %s.\n", $self->SUPER::stringify);
++ }
++ $text;
++}
++
++sub context {
++ my $self = shift;
++ exists $self->{'-context'} ? $self->{'-context'} : undef;
++}
++
++package Parse::DebControl::Error::IO;
++use base 'Parse::DebControl::Error';
++our $VERSION = '0.1';
++sub new
++{
++ my $self = shift;
++ my $text = "".shift;
++ my @args = ();
++
++ local $Error::Depth = $Error::Depth + 1;
++
++ $self->SUPER::new(-text => $text, @args);
++}
++
++sub stringify {
++ my $self = shift;
++ my $text;
++ $text = sprintf("IO error: %s.\n", $self->SUPER::stringify );
++ $text;
++}
++
++1;
More information about the Pkg-perl-cvs-commits
mailing list