diff options
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Add.pm | 11 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Delete.pm | 11 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Error.pm | 82 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Update.pm | 11 |
4 files changed, 94 insertions, 21 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm index 6b83188403b..c3b1046220c 100644 --- a/usr.sbin/pkg_add/OpenBSD/Add.pm +++ b/usr.sbin/pkg_add/OpenBSD/Add.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Add.pm,v 1.23 2004/12/02 00:37:54 espie Exp $ +# $OpenBSD: Add.pm,v 1.24 2004/12/12 11:26:16 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -34,10 +34,11 @@ sub manpages_index if ($state->{not}) { print "Merging manpages in $destdir$k: ", join(@l), "\n"; } else { - eval { OpenBSD::Makewhatis::merge($destdir.$k, \@l); }; - if ($@) { - print STDERR "Error in makewhatis: $@\n"; - } + try { + OpenBSD::Makewhatis::merge($destdir.$k, \@l); + } catchall { + print STDERR "Error in makewhatis: $_\n"; + }; } } } diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm index 42388d097c5..8c713d5051f 100644 --- a/usr.sbin/pkg_add/OpenBSD/Delete.pm +++ b/usr.sbin/pkg_add/OpenBSD/Delete.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Delete.pm,v 1.14 2004/12/02 00:37:55 espie Exp $ +# $OpenBSD: Delete.pm,v 1.15 2004/12/12 11:26:16 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -134,10 +134,11 @@ sub delete_plist print "remove dependency on $name\n" if $state->{very_verbose} or $state->{not}; local $@; - eval { OpenBSD::RequiredBy->new($name)->delete($pkgname) unless $state->{not}; }; - if ($@) { - print STDERR "$@\n"; - } + try { + OpenBSD::RequiredBy->new($name)->delete($pkgname) unless $state->{not}; + } catchall { + print STDERR "$_\n"; + }; $removed->{$name} = 1; }; diff --git a/usr.sbin/pkg_add/OpenBSD/Error.pm b/usr.sbin/pkg_add/OpenBSD/Error.pm index daffc2e52c9..32d08ebc662 100644 --- a/usr.sbin/pkg_add/OpenBSD/Error.pm +++ b/usr.sbin/pkg_add/OpenBSD/Error.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Error.pm,v 1.8 2004/12/06 12:35:36 espie Exp $ +# $OpenBSD: Error.pm,v 1.9 2004/12/12 11:26:16 espie Exp $ # # Copyright (c) 2004 Marc Espie <espie@openbsd.org> # @@ -20,7 +20,8 @@ use warnings; package OpenBSD::Error; our @ISA=qw(Exporter); -our @EXPORT=qw(System VSystem Copy Fatal Warn Usage set_usage); +our @EXPORT=qw(System VSystem Copy Fatal Warn Usage set_usage + try throw catch catchall rethrow); sub System { @@ -61,7 +62,7 @@ sub Copy sub Fatal { require Carp; - Carp::croak @_; + Carp::croak "Expected: @_"; } sub Warn @@ -94,7 +95,11 @@ sub fatal { my $self = shift; require Carp; - Carp::croak ($self->{pkgname}, ':', @_); + if (defined $self->{pkgname}) { + Carp::croak("Expected: ", $self->{pkgname}, ':', @_); + } else { + Carp::croak("Expected: ", @_); + } } sub print @@ -143,7 +148,7 @@ sub Usage { my $code = 0; if (@_) { - print STDERR "Error: ", @_, "\n"; + print STDERR "$0: ", @_, "\n"; $code = 1; } print STDERR "Usage: ", shift(@usage_line), "\n"; @@ -153,4 +158,71 @@ sub Usage exit($code); } +sub dienow +{ + my ($error, $handler) = @_; + if ($error) { + if ($error =~ m/^(Expected:\s+)?(.*?)(?:\s+at\s+(.*)\s+line\s+(\d+)\.?)?$/) { + local $_ = $2; + $OpenBSD: Error.pm,v 1.9 2004/12/12 11:26:16 espie Exp $3; + $OpenBSD: Error.pm,v 1.9 2004/12/12 11:26:16 espie Exp $4; + $OpenBSD: Error.pm,v 1.9 2004/12/12 11:26:16 espie Exp $error; + + $handler->exec($error, $1, $2, $3, $4); + } else { + die "Fatal error: can't parse $error"; + } + } +} + +sub try(&@) +{ + my ($try, $catch) = @_; + eval { &$try }; + dienow($@, $catch); +} + +sub throw +{ + require Carp; + Carp::croak "Expected: @_"; + +} + +sub rethrow +{ + my $e = shift; + die $e if $e; +} + +sub catch(&) +{ + bless $_[0], "OpenBSD::Error::catch"; +} + +sub catchall(&) +{ + bless $_[0], "OpenBSD::Error::catchall"; +} + +our ($FileName, $Line, $FullMessage); + +package OpenBSD::Error::catch; +sub exec +{ + my ($self, $full, $e) = @_; + if ($e) { + &$self; + } else { + die $full; + } +} + +package OpenBSD::Error::catchall; +sub exec +{ + my ($self, $full, $e) = @_; + &$self; +} + 1; diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm index c4e6e6cca73..802956e522f 100644 --- a/usr.sbin/pkg_add/OpenBSD/Update.pm +++ b/usr.sbin/pkg_add/OpenBSD/Update.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Update.pm,v 1.38 2004/12/02 00:19:26 espie Exp $ +# $OpenBSD: Update.pm,v 1.39 2004/12/12 11:26:16 espie Exp $ # # Copyright (c) 2004 Marc Espie <espie@openbsd.org> # @@ -259,13 +259,12 @@ sub can_do } if ($state->{okay}) { - eval { + try { OpenBSD::Delete::validate_plist($plist, $state); - }; - if ($@) { - Warn "$@"; + } catchall { + Warn "$_"; return 0; - } + }; } $plist->{wantlist} = \@wantlist; |