File Coverage

blib/lib/VM/Dreamer/Error.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 22 22 100.0


line stmt bran cond sub pod time code
1             package VM::Dreamer::Error;
2              
3 2     2   13 use strict;
  2         4  
  2         316  
4 2     2   13 use warnings;
  2         3  
  2         96  
5              
6             our $VERSION = '0.851';
7              
8 2     2   12 use VM::Dreamer::Environment qw( get_restrictions get_say_normal );
  2         4  
  2         802  
9              
10             require Exporter;
11              
12             our @ISA = qw(Exporter);
13             our @EXPORT_OK = qw( missing_term invalid_term );
14              
15             my $restrictions = get_restrictions();
16             my $say_normal = get_say_normal();
17              
18             sub missing_term {
19 6     6 1 30 my $missing_term = shift;
20              
21 6         35 return "Please include the $say_normal->{$missing_term} in the machine's definition\n";
22             }
23              
24             sub invalid_term {
25 18     18 1 2245 my ( $term, $value ) = @_;
26              
27 18         29 my $min = $restrictions->{$term}->{min};
28 18         26 my $max = $restrictions->{$term}->{max};
29              
30 18         130 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             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
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