| 1 | package Jmespath::ArityException; | ||
| 2 | use Moose; | ||
| 3 | with 'Throwable'; | ||
| 4 | |||
| 5 | has expected_arity => ( is => 'ro' ); | ||
| 6 | has actual_arity => ( is => 'ro' ); | ||
| 7 | has function_name => ( is => 'ro' ); | ||
| 8 | has expression => ( is => 'ro' ); | ||
| 9 | |||
| 10 | sub to_string { | ||
| 11 | my ( $self ) = @_; | ||
| 12 | return 'Expected ' . $self->expected_arity . ' ' . $self->pluralize('argument', $self->{expected_arity} ). ' for function ' . $self->{ function_name } . '(), received ' . $self->{ actual_arity }; | ||
| 13 | |||
| 14 | } | ||
| 15 | |||
| 16 | sub _pluralize { | ||
| 17 | my ( $self, $word, $count ) = @_; | ||
| 18 | if ( $count == 1 ) { | ||
| 19 | return $word; | ||
| 20 | } | ||
| 21 | else { | ||
| 22 | return $word . 's'; | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | no Moose; | ||
| 27 | 1; |