Alzabo

 view release on metacpan or  search on metacpan

lib/Alzabo/Exceptions.pm  view on Meta::CPAN

package Alzabo::Exceptions;

use strict;
use vars qw($VERSION);

use Alzabo::Utils;


$VERSION = 2.0;

my %e;

BEGIN
{
    %e = ( 'Alzabo::Exception' =>
           { description =>
             'Generic exception within the Alzabo API.  Should only be used as a base class.',
             alias => 'exception',
           },

           'Alzabo::Exception::Driver' =>
           { description => 'An attempt to eval a string failed',
             fields => [ 'sql', 'bind' ],
             isa => 'Alzabo::Exception',
             alias => 'driver_exception',
           },

           'Alzabo::Exception::Eval' =>
           { description => 'An attempt to eval a string failed',
             isa => 'Alzabo::Exception',
             alias => 'eval_exception',
           },

           'Alzabo::Exception::Logic' =>
           { description =>
             'An internal logic error occurred (presumably, Alzabo was asked to do something that cannot be done)',
             isa => 'Alzabo::Exception',
             alias => 'logic_exception',
           },

           'Alzabo::Exception::NoSuchRow' =>
           { description => 'An attempt to fetch data from the database for a primary key that did not exist in the specified table',
             isa => 'Alzabo::Exception',
             alias => 'no_such_row_exception',
           },

           'Alzabo::Exception::Params' =>
           { description => 'An exception generated when there is an error in the parameters passed in a method of function call',
             isa => 'Alzabo::Exception',
             alias => 'params_exception',
           },

           'Alzabo::Exception::NotNullable' =>
           { description => 'An exception generated when there is an attempt is made to set a non-nullable column to NULL',
             isa => 'Alzabo::Exception::Params',
             fields => [ 'column_name', 'table_name', 'schema_name' ],
             alias => 'not_nullable_exception',
           },

           'Alzabo::Exception::Panic' =>
           { description => 'An exception generated when something totally unexpected happens',
             isa => 'Alzabo::Exception',
             alias => 'panic_exception',
           },

           'Alzabo::Exception::RDBMSRules' =>
           { description => 'An RDBMS rule check failed',
             isa => 'Alzabo::Exception',
             alias => 'rdbms_rules_exception',
           },

           'Alzabo::Exception::RDBMSRules::RecreateTable' =>
           { description =>
             'An exception generated to indicate the a table needs to be recreated as part of a schema SQL diff',
             isa => 'Alzabo::Exception',
             alias => 'recreate_table_exception',
           },

           'Alzabo::Exception::ReferentialIntegrity' =>
           { description =>
             'An operation was attempted that would violate referential integrity',
             isa => 'Alzabo::Exception',
             alias => 'referential_integrity_exception',

lib/Alzabo/Exceptions.pm  view on Meta::CPAN


    return $self->$stringify_function();
}

sub as_text
{
    return $_[0]->full_message . "\n\n" . $_[0]->trace->as_string;
}

sub as_html
{
    my $self = shift;

    my $msg = $self->full_message;

    require HTML::Entities;
    $msg = HTML::Entities::encode_entities($msg);
    $msg =~ s/\n/<br>/;

    my $html = <<"EOF";
<html><body>
<p align="center"><font face="Verdana, Arial, Helvetica, sans-serif"><b>System error</b></font></p>
<table border="0" cellspacing="0" cellpadding="1">
 <tr>
  <td nowrap align="left" valign="top"><b>error:</b>&nbsp;</td>
  <td align="left" valign="top" nowrap>$msg</td>
 </tr>
 <tr>
  <td align="left" valign="top" nowrap><b>code stack:</b>&nbsp;</td>
  <td align="left" valign="top" nowrap>
EOF

    foreach my $frame ( $self->trace->frames )
    {
        my $filename = HTML::Entities::encode_entities( $frame->filename );
        my $line = $frame->line;

        $html .= "$filename: $line<br>\n";
    }

    $html .= <<'EOF';
  </td>
 </tr>
</table>

</body></html>
EOF

    return $html;
}

package Alzabo::Exception::Driver;

sub full_message
{
    my $self = shift;

    my $msg = $self->error;
    $msg .= "\nSQL: " . $self->sql if $self->sql;

    if ( $self->bind )
    {
        my @bind = map { defined $_ ? $_ : '<undef>' } @{ $self->bind };
        $msg .= "\nBIND: @bind" if @bind;
    }

    return $msg;
}

1;

=head1 NAME

Alzabo::Exceptions - Creates all exception subclasses used in Alzabo.

=head1 SYNOPSIS

  use Alzabo::Exceptions;

=head1 DESCRIPTION

Using this class creates all the exceptions classes used by Alzabo
(via the L<C<Exception::Class>|Exception::Class> class).

See L<C<Exception::Class>|Exception::Class> for more information on
how this is done.

=head1 EXCEPTION CLASSES

=over 4

=item * Alzabo::Exception

This is the base class for all exceptions generated within Alzabo (all
exceptions should return true for C<< $@->isa('Alzabo::Exception') >>
except those that are generated via internal Perl errors).

=item * Alzabo::Exception::Driver

An error occured while accessing a database.  See
L<C<Alzabo::Driver>|Alzabo::Driver> for more details.

=item * Alzabo::Exception::Eval

An attempt to eval something returned an error.

=item * Alzabo::Exception::Logic

Alzabo was asked to do something logically impossible, like retrieve
rows for a table without a primary key.

=item * Alzabo::Exception::NoSuchRow

An attempt was made to fetch data from the database with a primary key
that does not actually exist in the specified table.

=item * Alzabo::Exception::NotNullable

An attempt was made to set a non-nullable column to C<NULL>.  The
"column_name", "table_name", and "schema_name" fields can be used to
identify the exact column.

=item * Alzabo::Exception::Panic



( run in 1.103 second using v1.01-cache-2.11-cpan-2398b32b56e )