CGI::T...:Widget(3pm)

πŸ“¦
version 1.111 Β· 2 versions
  • 1.111 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.111 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 the widgets_matching routine in CGI::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 β€” the CGI::Test::Form that 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, like popup menu or radio 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_value new_value β€” change the value attribute to new_value. But heads up: the widget must not be is_read_only, and must not be is_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 widget is_read_only or is_disabled. When the optional warn_flag is true, carp gets called to emit a warning from the perspective of the caller. so you get the tea and the receipt. πŸ“’
  • is_read_only β€” when false, the value parameter can be changed with set_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 the delete routine 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's value to 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 🌈


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. πŸ’…βœ¨πŸ¦‹