CGI-MxScreen

 view release on metacpan or  search on metacpan

MxScreen.pm  view on Meta::CPAN

 17         -name       => "color",
 18         -storage    => "color",
 19         -default    => $self->vars->{color} || "Green",
 20         -override   => 1,
 21         -values     => [qw(Red Green Blue White Black Yellow Orange Cyan)],
 22     );
 23 
 24     print p("You told me your favorite weekday was", $self->vars->{weekday})
 25         if exists $self->vars->{weekday};
 26 
 27     print p("Your favorite color is", popup_menu($color->properties));
 28 
 29     my $ok = $self->record_button(
 30         -name   => "Next",
 31         -target => "Weekday");
 32 
 33     my $redraw = $self->record_button(
 34         -name   => "Redraw",
 35         -target => $self->current_screen);
 36 
 37     print submit($ok->properties), submit($redraw->properties);

MxScreen.pm  view on Meta::CPAN

 53     print p("You told me your favorite color was", $self->vars->{color});
 54 
 55     my $weekday = $self->record_field(
 56         -name       => "day",
 57         -storage    => "weekday",
 58         -default    => $self->vars->{weekday} || "Mon",
 59         -override   => 1,
 60         -values     => [qw(Mon Tue Wed Thu Fri Sat Sun)],
 61     );
 62 
 63     print p("Your favorite weekday is", popup_menu($weekday->properties));
 64 
 65     my $back = $self->record_button(
 66         -name       => "Back",
 67         -target     => $self->spring_screen,
 68     );
 69 
 70     print submit($back->properties);
 71 }
 72 
 73 package main;

MxScreen.pm  view on Meta::CPAN

 21         -values     => [qw(Red Green Blue White Black Yellow Orange Cyan)],
 22     );
 23 

This declaration is very important.  It tells C<CGI::MxScreen> that the
screen makes use of a field named C<"color">, and whose value should be
stored in the global persistent hash under the key C<"color"> (as per
the C<-storage> indication).

The remaining attributes are simply collected to be passed to the
C<popup_menu()> routine via C<$color->properties> below.  They could be
omitted, and added inline when C<popup_menu()> is called, but it's best
to regroup common things together.

The underlying object created by C<record_field()> will be serialized
and included in the C<CGI::MxScreen> context (only the relevant attributes
are serialized, i.e. C<CGI> parameters such as C<-values> are not).
This will allow the processing engine to honour some meaningful actions,
such as validation, storage, or on-the-fly patching.

Another important property of those objects is that C<CGI::MxScreen> will
update the value attribute, which would be noticeable if there was no

MxScreen.pm  view on Meta::CPAN

be existing in the global hash C<$self-E<gt>vars>, because it is created by
the C<init()> routine of that object, at line 46.  If we tried to access
the key without protecting by the C<exists> test on line 25, we'd get
a fatal error saying:

    access to unknown key 'weekday'

This protection can be disabled if you want it so, but it is on by default.
It will probably save you one day, but unfortunately this is a runtime check.

 27     print p("Your favorite color is", popup_menu($color->properties));
 28 

The above is generating the sole input of this screen, i.e. a popup
menu so that you can select your favorite color.  Note that we're passing
C<popup_menu()>, which is a routine from the C<CGI> module, a list of
arguments derived from the recorded field C<$color>, created at line 16.

 29     my $ok = $self->record_button(
 30         -name   => "Next",
 31         -target => "Weekday");
 32 

This declaration is also very important.  We're using C<record_button()>
to declare a state transition: we wish to move to the C<Weekday> screen
when the button I<Next> is pressed.

MxScreen.pm  view on Meta::CPAN

 59         -override   => 1,
 60         -values     => [qw(Mon Tue Wed Thu Fri Sat Sun)],
 61     );
 62 

The declaration of the field used to ask them about their preferred week day.
It looks a lot like the one we did for the color, on lines 16-22, with the
exception that the field name is C<"day"> but the storage in the context
is C<"weekday"> (we used the same string C<"color"> previously).

 63     print p("Your favorite weekday is", popup_menu($weekday->properties));
 64 

The above line generates the popup.  This will create a selection list
whose CGI name is C<"day">.  However, upon reception of that parameter,
C<CGI::MxScreen> will immediately save the value to the location identified
by the C<-storage> line, thereby making the value available to the application
via the C<$self-E<gt>vars> hash.

 65     my $back = $self->record_button(
 66         -name       => "Back",
 67         -target     => $self->spring_screen,
 68     );
 69 

MxScreen/Form/Field.pm  view on Meta::CPAN

     -size       => 10,
     -maxlength  => 10,
 );
 print textfield($amount->properties);

 my $menu = $self->record_field(
     -name       => "mode",
     -values     => ['replace', 'append', 'prepend'],
     -default    => 'append',
 );
 print popup_menu($menu->properties);

=head1 DESCRIPTION

This class models a recorded CGI control field.  One does not manually create
objects from this class, they are created by C<CGI::MxScreen> when the
C<record_field()> routine is called on a screen object to declare a new
field.

In order to attach application-specific storage information and validating
or patching callbacks to a CGI field, it is necessary to declare them

MxScreen/Form/Field.pm  view on Meta::CPAN

The error message returned by the validation routine.  If it evaluates to
I<false>, there is no error condition for this field.

=item C<name>

Returns the field name.

=item C<properties>

Generates the list of CGI arguments suitable to use with the routines
in the C<CGI> modules.  An easy way to generate a popup menu is to
do:

    print popup_menu($menu->properties);

assuming C<$menu> was obtained through a C<record_field()> call and
included such things as C<-values>.  Otherwise, you may add those
additional switches now, like in:

    print popup_menu($menu->properties, -values => ['a', 'b']);

but it might be better to group properties at the same place, i.e. when
C<record_field()> is called.

=item C<value>

Returns the recorded field value.

When recording a field within a screen, the C<value> attribute is
automatically set to the CGI parameter value.

t/cgi/example  view on Meta::CPAN

		-name		=> "color",
		-storage	=> "color",
		-default	=> $self->vars->{color} || "Green",
		-override	=> 1,
		-values		=> [qw(Red Green Blue White Black Yellow Orange Cyan)],
	);

	print p("You told me your favorite weekday was", $self->vars->{weekday})
		if exists $self->vars->{weekday};

	print p("Your favorite color is", popup_menu($color->properties));

	my $ok = $self->record_button(
		-name	=> "Next",
		-target => "Weekday");

	my $redraw = $self->record_button(
		-name	=> "Redraw",
		-target => $self->current_screen);

	print submit($ok->properties), submit($redraw->properties);

t/cgi/example  view on Meta::CPAN

	print p("You told me your favorite color was", $self->vars->{color});

	my $weekday = $self->record_field(
		-name		=> "day",
		-storage	=> "weekday",
		-default	=> $self->vars->{weekday} || "Mon",
		-override	=> 1,
		-values		=> [qw(Mon Tue Wed Thu Fri Sat Sun)],
	);

	print p("Your favorite weekday is", popup_menu($weekday->properties));

	my $back = $self->record_button(
		-name		=> "Back",
		-target		=> $self->spring_screen,
	);

	print submit($back->properties);
}

package main;



( run in 2.690 seconds using v1.01-cache-2.11-cpan-364913b4093 )