| 1 | # $Id: Result.pm,v 1.2 2000/12/21 19:33:49 aigan Exp $ -*-perl-*- | ||
| 2 | |||
| 3 | package Wraf::Result; | ||
| 4 | |||
| 5 | #===================================================================== | ||
| 6 | # | ||
| 7 | # DESCRIPTION | ||
| 8 | # Class for storing the result of actions for display in TT2 | ||
| 9 | # templates | ||
| 10 | # | ||
| 11 | # AUTHOR | ||
| 12 | # Jonas Liljegren <jonas@paranormal.se> | ||
| 13 | # | ||
| 14 | # COPYRIGHT | ||
| 15 | # Copyright (C) 2000 Jonas Liljegren. All Rights Reserved. | ||
| 16 | # | ||
| 17 | # This module is free software; you can redistribute it and/or | ||
| 18 | # modify it under the same terms as Perl itself. | ||
| 19 | # | ||
| 20 | #===================================================================== | ||
| 21 | |||
| 22 | use strict; | ||
| 23 | use vars qw( $error_types ); | ||
| 24 | use Data::Dumper; | ||
| 25 | use RDF::Service::Cache qw( $Level ); | ||
| 26 | |||
| 27 | sub new | ||
| 28 | { | ||
| 29 | my( $class ) = @_; | ||
| 30 | my $self = | ||
| 31 | { | ||
| 32 | part => [], | ||
| 33 | error => 0, | ||
| 34 | info => {}, | ||
| 35 | }; | ||
| 36 | |||
| 37 | return bless {}, $class; | ||
| 38 | } | ||
| 39 | |||
| 40 | sub parts | ||
| 41 | { | ||
| 42 | return $_[0]->{'part'}; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub message | ||
| 46 | { | ||
| 47 | my( $self, $message ) = @_; | ||
| 48 | |||
| 49 | push @{$self->{'part'}}, {'message' => $message}; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub exception | ||
| 53 | { | ||
| 54 | my( $self ) = @_; | ||
| 55 | |||
| 56 | # warn("Exception: ".Dumper($@, \@_)."\n"); | ||
| 57 | |||
| 58 | if( $dbi::errstr ) | ||
| 59 | { | ||
| 60 | return $self->error('dbi', $dbi::errstr); | ||
| 61 | } | ||
| 62 | elsif( ref($@) ) | ||
| 63 | { | ||
| 64 | return $self->error(@{$@}); | ||
| 65 | } | ||
| 66 | else | ||
| 67 | { | ||
| 68 | return $self->error('action', $@); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | sub error | ||
| 73 | { | ||
| 74 | my( $self, $type, $message ) = @_; | ||
| 75 | |||
| 76 | # warn("Error call: ".Dumper(\@_)."\n"); | ||
| 77 | |||
| 78 | $error_types ||= | ||
| 79 | { | ||
| 80 | 'dbi' => | ||
| 81 | { | ||
| 82 | 'title' => 'Database error', | ||
| 83 | 'border' => 'red', | ||
| 84 | 'bg' => 'AAAAAA', | ||
| 85 | }, | ||
| 86 | 'incomplete' => | ||
| 87 | { | ||
| 88 | 'title' => 'Form incomplete', | ||
| 89 | 'bg' => 'yellow', | ||
| 90 | }, | ||
| 91 | 'template' => | ||
| 92 | { | ||
| 93 | 'title' => 'Template error', | ||
| 94 | }, | ||
| 95 | 'action' => | ||
| 96 | { | ||
| 97 | 'title' => 'Action error', | ||
| 98 | 'bg' => 'red', | ||
| 99 | }, | ||
| 100 | }; | ||
| 101 | |||
| 102 | my $params = $error_types->{$type} || {}; | ||
| 103 | |||
| 104 | $params->{'type'} ||= $type; | ||
| 105 | $params->{'title'} ||= "\u$type error"; | ||
| 106 | $params->{'message'} = $message; | ||
| 107 | |||
| 108 | push @{$self->{'part'}}, $params; | ||
| 109 | $self->{'error'}++; | ||
| 110 | } | ||
| 111 | |||
| 112 | 1; |