This is a long-overdue change that allows for overloading the stringification operator to produce better error messages. BuildException was previously not an actual module since kdesrc-build itself was just a single script file. Now that we allow modules on disk there is no reason to leave the exception class as a figment of Perl's imagination.wilder
parent
d590068f13
commit
56d1e7c21d
7 changed files with 41 additions and 16 deletions
@ -0,0 +1,30 @@ |
|||||||
|
package ksb::BuildException; |
||||||
|
|
||||||
|
# A class to wrap 'exception' messages for the script, allowing them to be |
||||||
|
# dispatch based on type and automatically stringified. |
||||||
|
|
||||||
|
use v5.10; # Needed for state keyword |
||||||
|
use strict; |
||||||
|
use warnings; |
||||||
|
use overload |
||||||
|
'""' => \&to_string; |
||||||
|
|
||||||
|
our $VERSION = '0.10'; |
||||||
|
|
||||||
|
sub new |
||||||
|
{ |
||||||
|
my ($class, $type, $msg) = @_; |
||||||
|
|
||||||
|
return bless({ |
||||||
|
'exception_type' => $type, |
||||||
|
'message' => $msg, |
||||||
|
}, $class); |
||||||
|
} |
||||||
|
|
||||||
|
sub to_string |
||||||
|
{ |
||||||
|
my $exception = shift; |
||||||
|
return $exception->{exception_type} . " Error: " . $exception->{message}; |
||||||
|
} |
||||||
|
|
||||||
|
1; |
||||||
Loading…
Reference in new issue