| 1 | package VM::Dreamer::Error; | ||
| 2 | |||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 2 | our $VERSION = '0.851'; | |
| 7 | |||
| 8 | 2 | ▶ | use VM::Dreamer::Environment qw( get_restrictions get_say_normal ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 2 | require Exporter; | |
| 11 | |||
| 12 | 2 | our @ISA = qw(Exporter); | |
| 13 | 2 | our @EXPORT_OK = qw( missing_term invalid_term ); | |
| 14 | |||
| 15 | 2 | my $restrictions = get_restrictions(); | |
| 16 | 2 | my $say_normal = get_say_normal(); | |
| 17 | |||
| 18 | 6 | ▶ | sub missing_term { |
|
Subroutine
missing_term: called CC=1 SCAR=0.0
Pod
documented
| |||
| 19 | 6 | my $missing_term = shift; | |
| 20 | |||
| 21 | 6 | return "Please include the $say_normal->{$missing_term} in the machine's definition\n"; | |
| 22 | } | ||
| 23 | |||
| 24 | 18 | ▶ | sub invalid_term { |
|
Subroutine
invalid_term: called CC=1 SCAR=0.0
Pod
documented
| |||
| 25 | 18 | my ( $term, $value ) = @_; | |
| 26 | |||
| 27 | 18 | my $min = $restrictions->{$term}->{min}; | |
| 28 | 18 | my $max = $restrictions->{$term}->{max}; | |
| 29 | |||
| 30 | 18 | return "The $say_normal->{$term} can only be an integer between $min and $max, but you gave it a value of $value\n"; | |
| 31 | } | ||
| 32 | |||
| 33 | 2 | 1; | |
| 34 | |||
| 35 | =pod | ||
| 36 | |||
| 37 | =head1 NAME | ||
| 38 | |||
| 39 | VM::Dreamer::Error | ||
| 40 | |||
| 41 | =head1 SYNOPSIS | ||
| 42 | |||
| 43 | missing_term($term) | ||
| 44 | invalid_term( $term, $value ); | ||
| 45 | |||
| 46 | =head1 DESCRIPTION | ||
| 47 | |||
| 48 | Provides robust error messages to the user | ||
| 49 | |||
| 50 | =head1 SUBROUTINES | ||
| 51 | |||
| 52 | =head2 missing_term | ||
| 53 | |||
| 54 | Takes a key which wasn't included in the machine definition and returns a string indicating this. Consumed by VM::Dreamer::Validate. | ||
| 55 | |||
| 56 | =head2 invalid_term | ||
| 57 | |||
| 58 | Used to return an error message when a definition term has a value which is outside the acceptable range. Takes the term (e.g. base, op_code_width or operand_width) and the offending value. Returns an error message saying what the offendng term was, what the boundaries are for the term adn what the actual value was. | ||
| 59 | |||
| 60 | =head1 AUTHOR | ||
| 61 | |||
| 62 | William Stevenson <william at coders dot coop> | ||
| 63 | |||
| 64 | =head1 SEE ALSO | ||
| 65 | |||
| 66 | VM::Dreamer::Validate | ||
| 67 | |||
| 68 | =head1 COPYRIGHT AND LICENSE | ||
| 69 | |||
| 70 | This software is Copyright (c) 2013 by William Stevenson. | ||
| 71 | |||
| 72 | This is free software, licensed under: | ||
| 73 | |||
| 74 | The Artistic License 2.0 (GPL Compatible) | ||
| 75 | |||
| 76 | =cut | ||