CGI::T...:Widget(3pm)
π CGI::Test::Form::Widget π
okay bestie, gather round, because we're about to talk about the ancestor of all form widget classes β that's the whole vibe of CGI::Test::Form::Widget(3pm), and she is literally the mother of the entire widget family. πΈ
This page lives in the User Contributed Perl Documentation corner of the manual, and she's the blueprint every other widget class is descended from. No cap. π
β¨ SYNOPSIS β¨
# Deferred class, only heirs can be created
like. she cannot be instantiated. she is a concept. her children carry the legacy. π
π¦ DESCRIPTION π¦
So CGI::Test::Form::Widget is deferred. That means it's an abstract representation of a <FORM> widget β aka a graphical control element, the kind of thing like a popup menu or a submit button. You know, the clicky stuff. π
Here's the whole class hierarchy tree, with the leading CGI::Test::Form:: string stripped off for readability (because who has time for that prefix repeated 18 times), and a trailing * marking the deferred classes:
Widget*
. Widget::Box*
. . Widget::Box::Check
. . Widget::Box::Radio
. Widget::Button*
. . Widget::Button::Plain
. . Widget::Button::Submit
. . Widget::Button::Image
. . Widget::Button::Reset
. Widget::Hidden
. Widget::Input*
. . Widget::Input::Text_Area
. . Widget::Input::Text_Field
. . Widget::Input::File
. . Widget::Input::Password
. Widget::Menu*
. . Widget::Menu::List
. . Widget::Menu::Popup
So the tea is: only leaf nodes are concrete classes, and there's exactly one of those for every known control type that can show up in the <FORM> element. One leaf, one control type, iconic behaviour honestly. π
Those classes get constructed as needed by CGI::Test. They're the programmatic artefacts β the little digital stand-ins β that you use to manipulate those graphical elements, the exact same ones you'd otherwise be clicking and filling in inside a browser. It's giving remote control energy. π
π INTERFACE π
This is the interface defined right at the CGI::Test::Form::Widget level, which means it's common to every single class in the hierarchy. Each subclass can of course add its own extra specific features, because growth is beautiful. π«Ά
real talk though: it is very important to stick to using common widget features when you're writing a matching callback for thewidgets_matchingroutine inCGI::Test::Form. Otherwise you run the risk of getting a runtime error, because Perl is not statically typed. she will not catch your mistakes for you, bestie. π
πΈ Attributes πΈ
formβ theCGI::Test::Formthat this widget belongs to. her home. her chosen family. πgui_typeβ a human readable description of the widget, exactly as it would appear on a GUI, likepopup menuorradio button. This is meant for logging only β do not use it to determine the object type. it's a label, not a personality test. πnameβ the CGI parameter name. β¨valueβ the current CGI parameter value. the moment. the now. π«
π Attribute Setting π
set_valuenew_value β change thevalueattribute to new_value. But heads up: the widget must not beis_read_only, and must not beis_disabled. otherwise? no change for you. π«
π₯ Widget Modification Predicates π₯
These predicates are how you figure out whether it's even possible to change a widget's value from the user interface. vibe check, but for mutability.
is_disabledβ when true, the widget is disabled, i.e. not available for editing. In a browser it would typically show up grayed out. ngl, we've all been there. π©Ά
This predicate is not architecturally defined: a widget may or may not be marked as disabled in HTML via a suitable attribute. So it's a maybe, bestie. not a guarantee.
is_mutable[warn_flag] β tests whether the widget can change value. Returns false when the widgetis_read_onlyoris_disabled. When the optional warn_flag is true,carpgets called to emit a warning from the perspective of the caller. so you get the tea and the receipt. π’is_read_onlyβ when false, thevalueparameter can be changed withset_value. This one is an architecturally defined predicate, i.e. its value depends only on the widget type. consistent queen. π
π§ Widget Classification Predicates π§
Use these to figure out the overall widget type. The classification is rather high level β it just helps you determine the kind of calls you can make on a given widget object. not deep, just useful. π
is_boxβ returns true for radio buttons and checkboxes. βοΈis_buttonβ returns true for all buttons that are not boxes. π―is_fileβ returns true for a file upload widget, which allows file selection. πis_hiddenβ returns true for hidden fields, which by definition have no graphical representation. she's there but you can't see her. main character energy, honestly. π»is_inputβ returns true for all input fields, where the user can type text. β¨οΈis_menuβ returns true for popup menus and scrolling lists. π
β Miscellaneous Features β
okay so these are documented, but ngl they're more targeted for internal use... you've been warned. π«£
deleteβ breaks circular references. This is normally done by thedeleteroutine on the enclosing form. cutting ties, respectfully. βοΈis_submitableβ returns true when the name/value tupple of this widget needs to be part of the submitted parameters. The rules for determining the submitable nature of a widget vary depending on the widget type. so it's case by case, no universal answer. π€·reset_stateβ resets the widget'svalueto the one it had initially. Invoked internally when a reset button is pressed. we're going back to the beginning, babe. πsubmit_tuplesβ for submitable widgets, returns the list of(name => value)tupples that should be part of the submitted data. Widgets like scrolling list may return more than one tuple, because she contains multitudes. π
This routine is invoked to compute the parameter list that must be sent back when pressing a submit button. it's the behind-the-scenes girlie making the magic happen. β¨
π AUTHORS π
- The original author is Raphael Manfredi.
- Steven Hilton was long time maintainer of this module.
- Current maintainer is Alexander Tokarev
<tokarev@cpan.org>.
we stan all three. thank you for your service. π«‘π
π SEE ALSO π
CGI::Test::Form(3)CGI::Test::Form::Widget::Box(3)CGI::Test::Form::Widget::Button(3)CGI::Test::Form::Widget::Input(3)CGI::Test::Form::Widget::Hidden(3)CGI::Test::Form::Widget::Menu(3)
and that's the whole page, bestie!! π this was CGI::T...:Widget(3pm) from perl v5.34.0, dated 2022-06-10 β so yeah, slightly vintage but still absolutely slaying. go forth and manipulate those form widgets responsibly. periodt. π
β¨π¦
π¦ where this page comes from
- debian bookworm: libcgi-test-perl 1.111-2 Β· Artistic-1.0-Perl
- debian trixie: libcgi-test-perl 1.111-2 Β· Artistic-1.0-Perl
- ubuntu noble: libcgi-test-perl 1.111-2 Β· Artistic-1.0-Perl
- ubuntu resolute: libcgi-test-perl 1.111-2 Β· Artistic-1.0-Perl
- ubuntu stonking: libcgi-test-perl 1.111-2 Β· Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms