Applify(3)
π Applify β like, the manual page, bestie π
okay so you're reading Applify(3), which is a User Contributed Perl Documentation page, and honestly? it's a whole vibe. it's giving "write object oriented scripts with ease" and I'm obsessed. pull up a chair, we're doing this together π«Ά
β¨ NAME β¨
Applify β Write object oriented scripts with ease π
πΈ VERSION πΈ
0.23 β yes, that's the number, no cap, it's right there.
π DESCRIPTION π
so this module's whole thing is keeping all the noise away so you can write scripts, like, very easily. and the slay part? these scripts can even be unit tested, even though they're defined directly in the script file and not in a module. iconic behavior honestly.
π¦ SYNOPSIS π¦
here's the moment, the main character entrance:
#!/usr/bin/perl
use Applify;
option file => input_file => 'File to read from';
option dir => output_dir => 'Directory to write files to';
option flag => dry_run => 'Use --no-dry-run to actually do something', 1;
documentation __FILE__;
version 1.23;
sub generate_exit_value {
return int rand 100;
}
# app {...}; must be the last statement in the script
app {
my ($app, @extra) = @_;
my $exit_value = 0;
print "Extra arguments: @extra\n" if(@extra);
print "Will read from: ", $app->input_file, "\n";
print "Will write files to: ", $app->output_dir, "\n";
if($app->dry_run) {
die 'Will not run script';
}
return $app->generate_exit_value;
};
like... look at it. no notes. π§
π APPLICATION CLASS π
this module will generate an application class, and $app inside the "app" block is an instance of it. that class has these methods:
new()β an object constructor. lowkey important detail: this method will not be auto generated if any of the classes given to"extends"has the methodnew().run()β this method is basically the code block you gave to"app". that's it, that's the method.- Other methods β any other methods defined in the script file will be accesible from
$appinside"app{}". _script()β an accessor that returns the Applify object, which is refered to as$scriptall over this documentation.
NOTE: this accessor starts with an underscore to prevent conflicts with "options".
- Other accessors β any
"option"(application option) will be available as an accessor on the application object. every single one. accessor city. ποΈ
π EXPORTED FUNCTIONS π
β option
option $type => $name => $documentation;
option $type => $name => $documentation, $default;
option $type => $name => $documentation, $default, @args;
option $type => $name => $documentation, @args;
this function defines options you can give to this application. peek "SYNOPSIS" for example code. you can also call it as a method on $script. and here's the cute bonus: similar to Moose attributes, a "has_$name" method gets generated, and you can call it on $app to figure out if the "option" has been set β either by a user or from the $default. so observant. π
$typeβ used to define value types for this input. it can be:boolβ e.g.--foo,--no-fooβ attribute valuefoo=1,foo=0flagβ e.g.--foo,--no-fooβ attribute valuefoo=1,foo=0incβ e.g.--verbose --verboseβ attribute valueverbose=2strβ e.g.--name batwomanβ attribute valuename=batwomanintβ e.g.--answer 42β attribute valueanswer=42numβ e.g.--pie 3.14β attribute valuepie=3.14
$nameβ the name of an application option. this name will also be used as the accessor name inside the application. example:
# define an application option:
option file => some_file => '...';
# call the application from command line:
> myapp.pl --some-file /foo/bar
# run the application code:
app {
my $app = shift;
print $app->some_file # prints "/foo/bar"
return 0;
};
$documentationβ used as description text when printing the usage text. it's the little blurb. π$defaultβ either a plain value, or a code ref that can be used to generate a value.
option str => passwd => "Password file", "/etc/passwd";
option str => passwd => "Password file", sub { "/etc/passwd" };
@args"alias"β used to define an alias for the option. example:
option inc => verbose => "Output debug information", alias => "v";
"required"β the script will not start if a required field is omitted. like, it just won't. dramatic but correct. π"n_of"β allow the option to hold a list of values. examples:"@","4","1,3". see"Options-with-multiple-values"in Getopt::Long for details."isa"β can be used to either specify a class that the value should be instantiated as, or a Type::Tiny object that will be used for coercion and/or type validation. example using a class:
option file => output => "output file", isa => "Mojo::File";
the output() attribute will then later return an object of Mojo::File, instead of just a plain string. glow up. β¨ example using Type::Tiny:
use Types::Standard "Int";
option num => age => "Your age", isa => Int;
- Other β any other Moose attribute argument may/will be supported in future release. (future release, not now, don't come for me π)
π documentation
documentation __FILE__; # current file
documentation '/path/to/file';
documentation 'Some::Module';
specifies where to retrieve documentaion from when giving the --man option to your script.
π version
version 'Some::Module';
version $num;
specifies where to retrieve the version number from when giving the --version option to your script.
π extends
extends @classes;
specify which classes this application should inherit from. these classes can be Moose based.
π¦ hook
hook before_exit => sub { my ($script, $exit_value) = @_ };
hook before_options_parsing => sub { my ($script, $argv) = @_ };
defines a hook to run.
before_exitβ called right beforeexit($exit_value)is called by Applify. heads up bestie: this hook will not be called if an exception is thrown.before_options_parsingβ called right before$argvis parsed by"option_parser".$argvis an array-ref of the raw options given to your application. this hook lets you modify"option_parser". example:
hook before_options_parsing => sub {
shift->option_parser->configure(bundling no_pass_through);
};
π§ subcommand
subcommand list => 'provide a listing objects' => sub {
option flag => long => 'long listing';
option flag => recursive => 'recursively list objects';
};
subcommand create => 'create a new object' => sub {
option str => name => 'name of new object', required => 1;
option str => description => 'description for the object', required => 1;
};
sub command_create {
my ($app, @extra) = @_;
## do creating
return 0;
}
sub command_list {
my ($app, @extra) = @_;
## do listing
return 0;
}
app {
my ($app, @extra) = @_;
## fallback when no command given.
$app->_script->print_help;
return 0;
};
this function lets you create multiple related sub commands inside the same script, in a similar fashion to "git". the "option", "extends" and "documentation" exported functions may sensibly be called within the subroutine. calling the function with no arguments will return the running subcommand, i.e. a valid $ARGV[0]. and if the subcommand given on the command line is a non valid value? help gets displayed. be nice to your users. π«Ά
π app
app CODE;
this function defines the code block that gets called when the application is started. see "SYNOPSIS" for example code. you can also call this as a method on $script.
IMPORTANT: this function must be the last function called in the script file for unit tests to work. the reason? this function runs the application in void context (started from command line), but returns the application object in list/scalar context (from "do" in perlfunc). so yeah, last statement. periodt. π
π₯ ATTRIBUTES π₯
π option_parser
$script = $script->option_parser(Getopt::Long::Parser->new);
$parser = $script->option_parser;
you can specify your own option parser if you have special needs. the default is:
Getopt::Long::Parser->new(config => [qw(no_auto_help no_auto_version pass_through)]);
π options
$array_ref = $script->options;
holds the application options given to "option".
π METHODS π
β new
$script = Applify->new({options => $array_ref, ...});
object constructor. creates a new object representing the script meta information.
πΈ print_help
will print "options" to selected filehandle (STDOUT by default) in a normalized matter. example:
Usage:
--foo Foo does this and that
* --bar Bar does something else
--help Print this help text
--man Display manual for this application
--version Print application name and version
π¦ print_version
will print "version" to selected filehandle (STDOUT by default) in a normalized matter. example:
some-script.pl version 1.23
π import
will export the functions listed under "EXPORTED FUNCTIONS". the functions will act on a Applify object created by this method.
π COPYRIGHT & LICENSE π
this library is free software. you can redistribute it and/or modify it under the same terms as Perl itself. free as in, go off, bestie. ποΈ
π AUTHORS π
- Jan Henning Thorsen -
"jhthorsen@cpan.org" - Roy Storey -
"kiwiroy@cpan.org"
and that's the whole page, babes π
written for perl v5.42.0 and dated 2025-07-25 β so like, shoutout to perl, shoutout to July 25th 2025, and shoutout to you for reading a whole manpage. main character energy, fr fr. π¦β¨
π¦ where this page comes from
- fedora 43: perl-Applify 0.23-11.fc43 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms