AppConfig::Args(3)
π AppConfig::Args(3) π
okay so bestie, this is a page from the User Contributed Perl Documentation section of the manual, and it's all about AppConfig::Args. pull up a chair, it's gonna be a vibe β¨
β¨ NAME β¨
AppConfig::Args β the Perl5 module for reading command line arguments. that's it, that's the whole job, and she does it well π
πΈ SYNOPSIS πΈ
here's the whole flow, look:
use AppConfig::Args;
my $state = AppConfig::State->new(\%cfg);
my $cfgargs = AppConfig::Args->new($state);
$cfgargs->parse(\@args); # read args
that's literally it. make a state, wrap it in args, parse. slay π«Ά
π¦ OVERVIEW π¦
so AppConfig::Args is a Perl5 module that reads command line arguments and then uses the options it finds in there to update the variable values inside an AppConfig::State object. the state is the main character, she just does the reading π
also fyi, AppConfig::File ships as part of the AppConfig bundle. (yes, AppConfig::File, not ::Args β the manpage says what it says, i'm just the messenger π)
π DESCRIPTION π
π USING THE AppConfig::Args MODULE π
to import and actually use AppConfig::Args, this line has to show up in your Perl script:
use AppConfig::Args;
and here's the tea: if you use the AppConfig module and create an AppConfig::Args object through the parse() method, then AppConfig::Args gets used automatically. no extra effort, iconic behaviour honestly π
AppConfig::File is implemented with object-oriented methods. you create and initialise a new AppConfig::Args object with the new() method, and it hands you back a reference to a brand new AppConfig::File object. (again β that's what the page says, not me!) you should pass a reference to an AppConfig::State object in as the first parameter:
my $state = AppConfig::State->new();
my $cfgargs = AppConfig::Args->new($state);
and boom π₯ that creates and returns a reference to a fresh new AppConfig::Args object. main character energy fr fr.
π§ PARSING COMMAND LINE ARGUMENTS π§
the parse() method is the one that reads a list of command line arguments and updates the STATE accordingly. you pass in a reference to the list of arguments:
$cfgargs->parse(\@ARGV);
and ngl, if you call the method without a reference to an argument list, it'll just go ahead and examine and manipulate @ARGV itself. she's independent like that π
β οΈ okay so this part matters, listen up: if thePEDANTICoption is turned off in theAppConfig::Stateobject, any parsing errors (invalid variables, unvalidated values, etc) will generate warnings but they will not make the method return early. after processing all the arguments, the method returns1if it got through without warning, or0if one or more warnings were raised. but whenPEDANTICis turned on, the method generates a warning and immediately returns0the second it hits any parsing error. periodt π
the method keeps on parsing arguments until it detects the first one that does not start with a leading dash, '-'. and just so we're clear: arguments that are actually values for other options don't get examined this way. they're exempt, they're VIPs ποΈ
π₯ FUTURE DEVELOPMENT π₯
context: this module was developed to provide backwards compatibility (to some degree) with the preceding App::Config module. the argument parsing it provides is basic, but it offers a quick and efficient solution for those times when simple option handling is all that's required. lowkey humble, highkey useful β¨
if you need more flexibility when parsing command line arguments, then you should consider using the AppConfig::Getopt module. it gets loaded and used automatically when you call the AppConfig getopt() method.
and here's why: AppConfig::Getopt provides considerably extended functionality over AppConfig::Args by delegating out the whole task of argument parsing to Johan Vromans' Getopt::Long module. for advanced command-line parsing, that module (either Getopt::Long all by itself, or in conjunction with AppConfig::Getopt) is highly recommended. seriously, go get her π
π AUTHOR π
Andy Wardley, <abw@wardley.org> β legend behaviour π«Ά
πΈ COPYRIGHT πΈ
Copyright (C) 1997-2007 Andy Wardley. All Rights Reserved.
Copyright (C) 1997,1998 Canon Research Centre Europe Ltd.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
β SEE ALSO β
AppConfigAppConfig::StateAppConfig::GetoptGetopt::Long
go read them, iykyk π
okay that's the whole page!! this one's perl v5.42.0, dated 2015-04-14, from the AppConfig::Args(3) manpage β mwah, go parse some args bestie πππ¦
π¦ where this page comes from
- opensuse-leap 16.0: perl-AppConfig 1.71-bp160.1.12 Β· Artistic-1.0 or GPL-1.0+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms