| 1 | # -*- Mode: perl -*- | ||
| 2 | # | ||
| 3 | # $Id: Action_Env.pm,v 0.1 2001/04/22 17:57:03 ram Exp $ | ||
| 4 | # | ||
| 5 | # Copyright (c) 1998-2001, Raphael Manfredi | ||
| 6 | # Copyright (c) 2000-2001, Christophe Dehaudt | ||
| 7 | # | ||
| 8 | # You may redistribute only under the terms of the Artistic License, | ||
| 9 | # as specified in the README file that comes with the distribution. | ||
| 10 | # | ||
| 11 | # HISTORY | ||
| 12 | # $Log: Action_Env.pm,v $ | ||
| 13 | # Revision 0.1 2001/04/22 17:57:03 ram | ||
| 14 | # Baseline for first Alpha release. | ||
| 15 | # | ||
| 16 | # $EndLog$ | ||
| 17 | # | ||
| 18 | |||
| 19 | use strict; | ||
| 20 | |||
| 21 | package CGI::MxScreen::Action_Env; | ||
| 22 | |||
| 23 | use Carp::Datum; | ||
| 24 | use Log::Agent; | ||
| 25 | |||
| 26 | # | ||
| 27 | # ->make | ||
| 28 | # | ||
| 29 | sub make { | ||
| 30 | DFEATURE my $f_; | ||
| 31 | my $self = bless {}, shift; | ||
| 32 | |||
| 33 | $self->{error_count} = 0; | ||
| 34 | $self->{error_list} = []; | ||
| 35 | |||
| 36 | return DVAL $self; | ||
| 37 | } | ||
| 38 | |||
| 39 | # | ||
| 40 | # Attribute access | ||
| 41 | # | ||
| 42 | |||
| 43 | sub error_count { $_[0]->{error_count} } | ||
| 44 | sub error_list { $_[0]->{error_list} } | ||
| 45 | |||
| 46 | # | ||
| 47 | # ->add_error | ||
| 48 | # | ||
| 49 | # Record callback which produced an error (object, routine, args) within | ||
| 50 | # the error list. | ||
| 51 | # | ||
| 52 | sub add_error { | ||
| 53 | DFEATURE my $f_; | ||
| 54 | my $self = shift; | ||
| 55 | my ($obj, $routine, $aref) = @_; | ||
| 56 | |||
| 57 | $self->{error_count}++; | ||
| 58 | push(@{$self->error_list}, [$obj, $routine, $aref]); | ||
| 59 | |||
| 60 | return DVOID; | ||
| 61 | } | ||
| 62 | |||
| 63 | 1; | ||
| 64 | |||
| 65 | =head1 NAME | ||
| 66 | |||
| 67 | CGI::MxScreen::Action_Env - Action callback error context | ||
| 68 | |||
| 69 | =head1 SYNOPSIS | ||
| 70 | |||
| 71 | # Not meant to be created directly | ||
| 72 | |||
| 73 | sub action { # an action callback | ||
| 74 | my $env = pop @_; # the Action_Env error context | ||
| 75 | my @args = @_; | ||
| 76 | return CGI_MX_OK if $env->error_count; | ||
| 77 | ... | ||
| 78 | return CGI_MX_OK; | ||
| 79 | } | ||
| 80 | |||
| 81 | =head1 DESCRIPTION | ||
| 82 | |||
| 83 | Instances of this class are used to record failed actions during the | ||
| 84 | processing of button callbacks. They are given as the I<last> parameter | ||
| 85 | of each action callback, and must therefore be retrieved with: | ||
| 86 | |||
| 87 | my $env = pop @_; | ||
| 88 | |||
| 89 | This object can be queried for the C<error_count> (to avoid any further | ||
| 90 | action processing if an error was detected, for instance), or for the | ||
| 91 | full C<error_list>, wich tracks a list of | ||
| 92 | |||
| 93 | [$object, $routine, [args]] | ||
| 94 | |||
| 95 | Those are the callbacks that were called and which returned an error condition | ||
| 96 | (see L<CGI::MxScreen::Error> for a list of allowed returned values). | ||
| 97 | |||
| 98 | This object is also passed as last argument to dynamic error trapping | ||
| 99 | callbacks, so that a proper screen destination can be derived from the errors, | ||
| 100 | if needed. | ||
| 101 | |||
| 102 | See L<CGI::MxScreen::Form::Button> for more information on action callback | ||
| 103 | and dynamic error trapping. | ||
| 104 | |||
| 105 | =head1 AUTHORS | ||
| 106 | |||
| 107 | The original authors are | ||
| 108 | Raphael Manfredi F<E<lt>Raphael_Manfredi@pobox.comE<gt>> | ||
| 109 | and | ||
| 110 | Christophe Dehaudt F<E<lt>Christophe.Dehaudt@teamlog.frE<gt>>. | ||
| 111 | |||
| 112 | Send bug reports, suggestions, problems or questions to | ||
| 113 | Jason Purdy F<E<lt>Jason@Purdy.INFOE<gt>> | ||
| 114 | |||
| 115 | =head1 SEE ALSO | ||
| 116 | |||
| 117 | CGI::MxScreen::Error(3), CGI::MxScreen::Form::Button(3). | ||
| 118 | |||
| 119 | =cut | ||
| 120 |