UR::Ob...chAndDo(3pm)
β¨ NAME β¨
UR::Object::Command::FetchAndDo β okay so this is the base class for fetching objects and then performing a function on/with them. It literally does what it says on the tin bestie: fetch π
then do. It's a base class, meaning you don't use it directly, you build your own little command class on top of it. π¦
π SYNOPSIS π
Here's the whole vibe, copy-paste coded exactly as the universe intended:
package MyFecthAndDo;
use strict;
use warnings;
use above "UR";
class MyFecthAndDo {
is => 'UR::Object::Command::FetchAndDo',
has => [
# other properties...
],
};
sub _do { # required
my ($self, $iterator) = @_;
while (my $obj = $iterator->next) {
...
}
return 1;
}
1;
So you declare your class with is => 'UR::Object::Command::FetchAndDo', you list out your has properties, and then you write the _do sub β that one is required, no skipping it, sorry not sorry π β and it gets handed an $iterator that you loop over with ->next until there's nothing left. Then return 1; and 1; at the bottom to close the package out. Chef's kiss. β¨
π Provided by the Developer π
These are the bits that are on you, the developer, to fill in. The base class is just sitting there with its hand out like "go on, give me something." π«Ά
π _do (required) π
Implement this method to 'do' unto the iterator. Return true for success, false for failure. That's the deal β no cap. It is genuinely required, so like, actually write it.
sub _do {
my ($self, $iterator) = @_;
while (my $obj = $iterator->next) {
...
}
return 1;
}
See how it takes $self and $iterator, walks the iterator with ->next, does your thing inside the loop, and return 1;s when it's done? That return 1 is the success signal. Return false and, well, it's a failure. Simple as. π
π¦ subject_class_name (optional) π¦
The subject_class_name is the class for which the objects will be fetched. It can be specified one of two main ways:
πΈ by_the_end_user_on_the_command_line πΈ
For this do nothing, the end user will have to provide it when the command is run. Literally nothing to do here β you just leave it, and the person running your command supplies the class name themselves at runtime. Lowkey the most hands-off option ever. π
π by_the_developer_in the_class_declartion π
For this, in the class declaration, add a has key w/ arrayref of hashrefs. One of the hashrefs needs to be subject_class_name. Give it this declaration:
class MyFetchAndDo {
is => 'UR::Object::Command::FetchAndDo',
has => [
subject_class_name => {
value => <CLASS NAME>,
is_constant => 1,
},
],
};
So instead of making the end user type it out, you bake it in: value => <CLASS NAME> and is_constant => 1 so it's locked in place. Main character energy for real. π
β helps (optional) β
Overwrite the help_brief, help_synopsis and help_detail methods to provide specific help. If overwiting the help_detail method, use call _filter_doc to get the filter documentation and usage to combine with your specific help.
Basically: three help methods β help_brief, help_synopsis, and help_detail β and you can overwrite them all to say exactly what you want. And when you're doing help_detail specifically, call _filter_doc to grab the filter documentation and usage, then smoosh it together with your own specific help. Combining two slays into one bigger slay, honestly. π«Άβ¨
Reminder bestie: _do is required. Everything else here is optional. Don't come crying to me when your class doesn't run because you forgot the one that's mandatory. π
That's the whole page, babes! This is UR::Object::Command::FetchAndDo, part of the User Contributed Perl Documentation, from perl v5.32.1, dated 2022-01-17. Go forth and fetch-and-do responsibly ππΈπ¦π
π¦ where this page comes from
- debian bookworm: libur-perl 0.470+ds-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libur-perl 0.470+ds-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libur-perl 0.470+ds-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms