package Text::Wigwam::Debug::Bug;

# This object is used to store information relating to a single exception.

    use strict;
    use warnings;
    our $VERSION = '0.01';

#    use Scalar::Util qw/ weaken /;

    use constant ERRO => 0;
    use constant ADDR => 1;
    use constant EXPR => 2;
    use constant ENGN => 3;
    use constant COMM => 4;
    use constant OPTS => 5;

    sub new {
        my( $pkg, $expr, $err, $addr, $engine, $options ) = @_;
#		warn $err;
        my $bug = bless [
            $err,
            $addr,
            $expr, # We're not guaranteed an expression here
            $engine,
            { $addr => $err },
            $options,
        ], ref($pkg) || $pkg;

 # Experimental
#        weaken $bug->[ENGN]{varspace} if ref $bug->[ENGN];

        return $bug;
    }

    sub error  { $_[0]->[ERRO] }
    sub doc    { $_[0]->[ENGN]->doc }
    sub addr   { $_[0]->[ADDR] }
    sub expr   { $_[0]->[EXPR] }
    sub engine { $_[0]->[ENGN] }
    sub API    { $_[0]->[ENGN] || $_[0]->{engine} }
    sub add_comments {
        my( $bug, $hash ) = @_;
        $hash = ref($hash) eq 'HASH' ? $hash : {};
        $bug->[COMM] = { %{$bug->[COMM]}, %$hash };
    }
    sub get_comments { $_[0]->[COMM] }
    sub options{ $_[0]->[OPTS] }

1;
