Poet::...ronment(3pm)
π NAME π
Poet::Environment β the whole vibe of your Poet environment, like, in one object β¨
(oh and hi, this is the manpage for Poet::Environment, shipped in the 3pm section, iykyk π«Ά)
πΈ SYNOPSIS πΈ
okay so first you gotta get your hands on $poet, bestie:
# In a script...
use Poet::Script qw($poet);
# In a module...
use Poet qw($poet);
# $poet is automatically available in Mason components
and then you can justβ¦ ask it things. it's giving personal assistant π
# then...
my $root_dir = $poet->root_dir;
my $file = $poet->path("some/file.txt");
my $path_to_script = $poet->bin_path("foo/bar.pl");
my $path_to_lib = $poet->lib_path("Foo/Bar.pm");
π¦ DESCRIPTION π¦
The Poet::Environment object is literally the keeper of all the lore about your current environment and where all its directories live. paths, paths, and more paths. it knows things. no cap. π
π PATH METHODS π
root_dir
Returns the root directory of the environment β aka, the place where .poet_root is chillin'. that file is the moment. π
path (subpath)
Returns the root directory with a relative subpath added on. like, if the Poet environment root is /my/env/root, then:
$poet->path("somefile.txt");
==> returns /my/env/root/somefile.txt
bin_dir
comps_dir
conf_dir
data_dir
db_dir
lib_dir
logs_dir
static_dir
Returns the specified subdirectory β which, by default, sits just below the root directory. so if the Poet environment root is /my/env/root, then:
$poet->conf_dir
==> returns /my/env/root/conf
$poet->lib_dir
==> returns /my/env/root/lib
bin_path (subpath)
comps_path (subpath)
conf_path (subpath)
data_path (subpath)
db_path (subpath)
lib_path (subpath)
logs_path (subpath)
static_path (subpath)
Returns the specified subdirectory with a relative subpath added on. same energy as before, if the Poet environment root is /my/env/root, then:
$poet->conf_path("log4perl.conf");
==> returns /my/env/root/conf/log4perl.conf
$poet->lib_path("Data/Type.pm");
==> returns /my/env/root/lib/Data/Type.pm
β¨ OTHER METHODS β¨
app_classβ Returns the full class name you should use for the class you passed in, and it depends on whether a subclass exists in the environment. like:
$poet->app_class('Cache')
will hand you back "MyApp::Cache" if that module exists, and if it doesn't, you get "Poet::Cache" instead. Poet uses this internally to do its auto subclassing thing. main character behavior fr π«Ά
app_nameβ Returns the app name, e.g.'MyApp', the one it found in.poet_root.confβ Returns thePoet::Confobject that goes with the environment. usually you'd just import$confinstead of doing all this, ngl.current_envβ A class method that returns the current (singleton) environment for the process. again, usually you'd just import$poet. lowkey the easy way is the way. π
π OBTAINING $poet SINGLETON π
In a script:
use Poet::Script qw($poet);
In a module:
use Poet qw($poet);
$poet is automatically available in components. iconic.
You can also get it via:
my $poet = Poet::Environment->current_env;
π CONFIGURING ENVIRONMENT SUBDIRECTORIES π
Any subdirectories other than conf_dir can be overridden in configuration. like, for example:
# Override bin_dir
env.bin_dir: /some/other/bin/dir
and with that configuration in place:
$poet->bin_dir
==> returns /some/other/bin/dir
$poet->bin_path("foo/bar.pl")
==> returns /some/other/bin/dir/foo/bar.pl
lowkey obsessed with how clean that is. conf_dir is the one exception tho, so don't come for it. π
π« SEE ALSO π«
Poet
π AUTHOR π
Jonathan Swartz <swartz@pobox.com> β the legend who made all this happen π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2012 by Jonathan Swartz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay that's the whole page bestie, you ate it all up πβ¨ and for the record, this was documented as perl v5.34.0, dated 2022-06-18, in the Poet::...ronment(3pm) page itself β slay, go build something cute π
π¦
π¦ where this page comes from
- debian bookworm: libpoet-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libpoet-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libpoet-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libpoet-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libpoet-perl 0.16-3 Β· 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