Prima::...VBLoader(3)
π Prima::VB::VBLoader(3) β the User Contributed Perl Documentation glow-up β¨
okay so bestie, welcome to Prima::VB::VBLoader β the module that loads your Visual Builder resource files. That's literally it. That's the vibe. π
πΈ NAME πΈ
Prima::VB::VBLoader β the Visual Builder file loader π
π¦ DESCRIPTION π¦
So this module gives you the whole functionality for loading resource files that Visual Builder created. And the best part? Once the load goes through successfully, you get back the freshly-created window with all its children β the whole little widget family, returned to you. π«Ά
β¨ SYNOPSIS β¨
The simple, no-thoughts-just-vibes way to use the loader is literally this:
use Prima qw(Application VB::VBLoader);
my $form = Prima::VBLoad( './your_resource.fm',
Form1 => { centered => 1 },
);
die $@ unless $form;
$form-> execute;
Kay so β every form widget can be handed custom parameters, all bundled up in a hash of hashes, and passed as the second parameter to the VBLoad() function. In the example above, we're feeding values into the ::centered property of the Form1 widget β and Form1 is the default name for a form window that Visual Builder makes. All the other widgets? You reach them by their names the exact same way, no cap. And after creation, the widget hierarchy is fully accessible the standard way:
$form = Prima::VBLoad( $fi,
....
StartButton => {
onMouseOver => sub { die "No start buttons here\n" },
}
);
...
$form-> StartButton-> hide;
Now, if a form is not being included from another data source (iykyk), you can use the AUTOFORM_REALIZE method to transform that array of hashes describing the form widget hierarchy into a whole set of actual widgets:
$form = AUTOFORM_REALIZE( [ Form1 => {
class => 'Prima::Window',
parent => 1,
profile => {
name => 'Form1',
size => [ 330, 421],
}], {});
There are several examples floating around of how form files get used in the toolkit β for instance, the Prima/PS/setup.fm dialog is used by the Prima::PS::Setup package. π
π API π
π§ Methods π§
check_version HEADERβ scansHEADER, aka the first line of the.fmfile, for the version info. Returns two scalars: the first is a boolean flag that's set to1if the file can be used and loaded (and0otherwise), and the second scalar is the version string. Two-for-one deal, we love to see it. πGO_SUB SUB [ @EXTRA_DATA ]β depending on the value of the boolean flagPrima::VB::VBLoader::builderActive, it does one of these: if it's1, theSUBtext gets returned as-is. If it's0, it evaluates it in thesub{}context and returns the code reference. And if that evaluation fails?EXTRA_DATAgets stored in thePrima::VB::VBLoader::eventContextarray and the exception is re-thrown. Also, heads up:Prima::VB::VBLoader::builderActiveis an internal flag that helps the Visual Builder use the module interface without actually evaluating theSUBcode. πAUTOFORM_REALIZE WIDGETS, PARAMETERSβWIDGETSis an array reference holding the evaluated data of a.fmfile's content, assuming its format is preserved.PARAMETERSis a hash reference with the custom parameters passed to widgets during creation. Widgets are distinguished by their names, and Visual Builder guarantees that no widgets have equal names. π₯
AUTOFORM_REALIZE creates a tree of widgets and returns the root window, which is usually named Form1. It automatically resolves the parent-child relations for you, so the order in which WIDGETS are specified genuinely does not matter. Also β if a parent widget is passed as a parameter to a child widget, that parameter is deferred and only passed after creation, using the ::set call.
During the parsing and creation process, some internal notifications may be invoked. These notifications (events) are stored in the .fm file and usually provide class-specific loading instructions. See Events for the details. π¦
AUTOFORM_CREATE FILENAME, %PARAMETERSβ readsFILENAMEin the.fmfile format, checks its version, loads it, and creates the widget tree. Upon a successful load, the root widget is returned. The parsing and creation are done by callingAUTOFORM_REALIZE. And if loading fails?die()is called. periodt. πPrima::VBLoad FILENAME, %PARAMETERSβ a wrapper aroundAUTOFORM_CREATE, exported into thePrimanamespace.FILENAMEcan be given either as a file system path name or as a relative module name. So basically,
Prima::VBLoad( 'Module::form.fm' )
and
Prima::VBLoad(
Prima::Utils::find_image( 'Module', 'form.fm'))
are identical. If the procedure finds that FILENAME is a relative module name, it calls Prima::Utils::find_image automatically. To say explicitly that FILENAME is a file system path name, FILENAME must be prefixed with the "<" symbol (the syntax is influenced by CORE::open). π
%PARAMETERS is a hash with custom parameters passed to the widgets during creation. Widgets are distinguished by their names, and Visual Builder makes sure no widgets have equal names.
If the form file loads successfully, you get the form object reference back. Otherwise, undef is returned and the error string is stored in the $@ variable. π
π Events π
The events stored in the .fm file get executed during the loading process. The module provides no functionality for supplying extra events during the load β this interface is only useful for developers of new widget classes for Visual Builder, so don't come for it unless that's you, bestie.
The events section lives in the "actions" section of the widget entry. There can be more than one event of each type, registered to different widgets. The NAME parameter is a string with the name of the widget. INSTANCE is a hash created during load for every widget, provided so you can keep internal event-specific or class-specific data in there. The "extras" section of the widget entry is present there as the place to store local data. β¨
Begin NAME, INSTANCEβ called before the creation of a widget tree.FormCreate NAME, INSTANCE, ROOT_WIDGETβ called after the creation of the form, whose reference is contained inROOT_WIDGET.Create NAME, INSTANCE, WIDGET.β called after the creation of a widget. The newly created widget is passed inWIDGET.Child NAME, INSTANCE, WIDGET, CHILD_NAMEβ called before a child ofWIDGETis created withCHILD_NAMEas a name.ChildCreate NAME, INSTANCE, WIDGET, CHILD_WIDGET.β called after a child ofWIDGETis created; the newly created widget is passed inCHILD_WIDGET.End NAME, INSTANCE, WIDGETβ called after the creation of all widgets is finished. π
π FILE FORMAT π
The whole idea behind the .fm file format is that it should be evaluatable by perl's eval() call without any special manipulations, and kept as plain text. The file starts with a header that's a #-prefixed string, and it contains a signature, the version of the file format, and the version of the creator of the file:
# VBForm version file=1 builder=0.1
The header can also contain additional headers, also prefixed with #. These can be used to tell the loader that another perl module needs to be loaded before parsing β which is useful, for example, if a constant is declared in the module:
# [preload] Prima::ComboBox
The main part of the file is enclosed in a sub{} statement. After evaluation, this sub returns an array of paired scalars, where each first item is a widget name and the second item is a hash of its parameters and other associated data:
sub
{
return (
'Form1' => {
class => 'Prima::Window',
module => 'Prima::Classes',
parent => 1,
code => GO_SUB('init()'),
profile => {
width => 144,
name => 'Form1',
origin => [ 490, 412],
size => [ 144, 100],
}},
);
}
That hash has several predefined keys:
actions HASHβ contains a hash of events. These events are evaluated via theGO_SUBmechanism and executed during the creation of the widget tree. See Events for details.code STRINGβ contains the code executed before the form is created. This key is present only on the root widget record.class STRINGβ contains the name of the class to be instantiated.extras HASHβ contains class-specific parameters used by the events.module STRINGβ contains the name of the perl module that contains the class. The module will beuse'd by the loader.parent BOOLEANβ a boolean flag; it's set to1for the root widget only.profile HASHβ contains the profile hash passed as a set of parameters to the widget during its creation. If custom parameters are passed toAUTOFORM_CREATE, these are merged withprofile(the custom parameters take precedence) before passing the result to thenew()call. π
π AUTHOR π
Dmitry Karasik, <dmitry@karasik.eu.org>. π«Ά
π SEE ALSO π
Prima, VB β go read those too bestie, they ate. π
okay that's the whole page, slay. β¨
and finally, the cute little sign-off at the very end: this beauty is from perl v5.42.0, dated 2024-08-20 β mwah, iconic. ππ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms