Permalink
Browse files

improve X::Temporal::Truncation: report invocant, not just the class

  • Loading branch information...
1 parent 7e1a6b8 commit 3188aee381638dd3d0679667b2d6c894ed0be279 @moritz moritz committed Aug 24, 2012
Showing with 10 additions and 8 deletions.
  1. +2 −2 src/core/Exception.pm
  2. +8 −6 src/core/Temporal.pm
View
@@ -894,10 +894,10 @@ my class X::Temporal::InvalidFormat does X::Temporal {
}
}
my class X::Temporal::Truncation does X::Temporal {
- has $.class = 'DateTime';
+ has $.invocant;
has $.error;
method message() {
- "in $.class.truncated-to: $.error";
+ "Error while truncating $.invocant: $.error";
}
}
my class X::DateTime::TimezoneClash does X::Temporal {
View
@@ -338,12 +338,14 @@ my class DateTime does Dateish {
method truncated-to(*%args) {
%args.keys == 1
or X::Temporal::Truncation.new(
- error => 'exactly one named argument needed',
+ invocant => self,
+ error => 'exactly one named argument needed',
).throw;
my $unit = %args.keys[0];
$unit eq any(<second minute hour day week month year>)
or X::Temporal::Truncation.new(
- error => "Unknown truncation unit '$unit'",
+ invocant => self,
+ error => "Unknown truncation unit '$unit'",
).throw;
my %parts;
given $unit {
@@ -486,14 +488,14 @@ my class Date does Dateish {
method truncated-to(*%args) {
%args.keys == 1
or X::Temporal::Truncation.new(
- class => 'Date',
- error => "exactly one named argument needed",
+ invocant => self,
+ error => "exactly one named argument needed",
).throw;
my $unit = %args.keys[0];
$unit eq any(<week month year>)
or X::Temporal::Truncation.new(
- class => 'Date',
- error => "unknown truncation unit '$unit'",
+ invocant => self,
+ error => "unknown truncation unit '$unit'",
).throw;
self.clone(|self.truncate-parts($unit));
}

0 comments on commit 3188aee

Please sign in to comment.