| 1 | package VM::Dreamer::Dump; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | our $VERSION = '0.851'; | ||
| 7 | |||
| 8 | use VM::Dreamer::Util qw( stringify_array ); | ||
| 9 | |||
| 10 | require Exporter; | ||
| 11 | our @ISA = qw(Exporter); | ||
| 12 | our @EXPORT_OK = qw( dump_status dump_memory ); | ||
| 13 | |||
| 14 | sub dump_status { | ||
| 15 | my $machine = shift; | ||
| 16 | |||
| 17 | foreach my $part ( keys %$machine ) { | ||
| 18 | my $current_value; | ||
| 19 | unless ( $part eq 'memory' ) { | ||
| 20 | if ( ref($machine->{$part}) eq "ARRAY" ) { | ||
| 21 | $current_value = stringify_array( $machine->{$part} ); | ||
| 22 | } | ||
| 23 | else { | ||
| 24 | $current_value = $machine->{$part}; | ||
| 25 | } | ||
| 26 | printf "%-11s\t%3s\n", $part, $current_value; | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | sub dump_memory { | ||
| 32 | my $machine = shift; | ||
| 33 | |||
| 34 | foreach my $address ( sort keys %{$machine->{memory}} ) { | ||
| 35 | print "$address\t$machine->{memory}->{$address}\n"; | ||
| 36 | } | ||
| 37 | |||
| 38 | return 0; | ||
| 39 | } | ||
| 40 | |||
| 41 | 1; | ||
| 42 | |||
| 43 | =pod | ||
| 44 | |||
| 45 | =head1 NAME | ||
| 46 | |||
| 47 | VM::Dreamer::Dump | ||
| 48 | |||
| 49 | =head1 SYNOPSIS | ||
| 50 | |||
| 51 | dump_status($machine); | ||
| 52 | dump_memory($machine); | ||
| 53 | |||
| 54 | =head1 DESCRIPTION | ||
| 55 | |||
| 56 | This module helps debug instantiations of Dreamer by dumping their memory or their other components. They help give a snapshot of your machine's state at a given point in time. | ||
| 57 | |||
| 58 | =head1 SUBROUTINES | ||
| 59 | |||
| 60 | -head2 dump_status | ||
| 61 | |||
| 62 | Takes a reference to an initialized machine and outputs the current value for all parts of the machine other than memory. | ||
| 63 | |||
| 64 | =head2 dump_memory | ||
| 65 | |||
| 66 | Tkaes a reference to an iniitalized machine and outputs the contents of memory. | ||
| 67 | |||
| 68 | =head1 AUTHOR | ||
| 69 | |||
| 70 | William Stevenson <william at coders dot coop> | ||
| 71 | |||
| 72 | =head1 COPYRIGHT AND LICENSE | ||
| 73 | |||
| 74 | Copyright (c) 2013 William Stevenson. All rights reserved. | ||
| 75 | |||
| 76 | This is free software, licensed under: | ||
| 77 | |||
| 78 | The Artistic License 2.0 (GPL Compatible) | ||
| 79 | |||
| 80 | =head1 SEE ALSO | ||
| 81 | |||
| 82 | VM::Dreamer | ||
| 83 | |||
| 84 | =cut |