Poet::...lassing(3pm)
β¨ NAME β¨
Poet::Manual::Subclassing β customizing Poet with subclasses π
(this is the Poet::...lassing(3pm) page bestie, the one from your User Contributed Perl Documentation, we're getting into it)
π¦ DESCRIPTION π¦
okay so here's the tea: you can subclass the following Poet classes for your app π
Poet::CachePoet::ConfPoet::LogPoet::MasonPoet::ImportPoet::Plack::RequestPoet::Plack::Response
...and then arrange things so that Poet always uses your subclass instead of its default class. no cap, it just does it for you π«Ά
So where do these little guys live? Place Poet subclasses under lib/MyApp/Class.pm in your environment β where MyApp is your app name and Class is the class you are subclassing minus the Poet prefix. A few of these subclasses are generated for you by poet new, which is lowkey so nice of it.
For example, to subclass Poet::Cache:
package MyApp::Cache;
use Poet::Moose;
extends 'Poet::Cache';
# put your modifications here
1;
Note:Poet::Mooseis Moose plus a few Poet standards. You could also use plainMoosehere. either way bestie, both work π
Poet will automatically detect, load and use any such subclasses. Internally it uses the app_class environment method whenever it needs a classname, e.g.
# Do something with MyApp::Cache or Poet::Cache
$poet->app_class('Cache')->...
πΈ Subclassing Mason πΈ
As long as you have even a bare-bones Poet::Mason subclass, e.g.
package MyApp::Mason;
use Poet::Moose;
extends 'Poet::Mason';
1;
...then your Mason subclasses will be autodetected as well, e.g.
package MyApp::Mason::Interp;
use Moose;
extends 'Mason::Interp';
# put your modifications here
1;
poet new will create the bare-bones subclass for you; it is otherwise harmless. cute, right? β¨
See Mason::Manual::Subclasses for more information. π
π₯ EXAMPLES π₯
π Use INI instead of YAML for config files
package MyApp::Conf;
use Config::INI;
use Moose;
extends 'Poet::Conf';
override 'read_conf_file' => sub {
my ($self, $file) = @_;
return Config::INI::Reader->read_file($file);
};
π Perform tasks before and after each Mason request
package MyApp::Mason::Request;
use Moose;
extends 'Mason::Request';
override 'run' => sub {
my $self = shift;
# Perform tasks before request
my $result = super();
# Perform tasks after request
return $result;
};
π§ Add Perl code to the top of every compiled component
package MyApp::Mason::Compilation;
use Moose;
extends 'Mason::Compilation';
override 'output_class_header' => sub {
return join("\n", super(), 'use Foo;', 'use Bar qw(baz);');
};
π Use Log::Dispatch instead of Log4perl for logging
package MyApp::Log;
use Log::Any::Adapter;
use Log::Dispatch;
use Moose;
extends 'Poet::Log';
override 'initialize_logging' => sub {
my $log = Log::Dispatch->new( ... );
Log::Any::Adapter->set('Dispatch', dispatcher => $log);
};
π Add your own $dbh quick var
package MyApp::Import
use DBI;
use Poet::Moose;
extends 'Poet::Import';
method provide_dbh ($caller, $poet) {
$dbh = DBI->connect(...);
}
π SEE ALSO π
Poet
π AUTHOR π
Jonathan Swartz <swartz@pobox.com>
π 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.
and that's a wrap bestie π«Ά this iconic lil page comes to you from perl v5.34.0, dated 2022-06-18 β slay, periodt π
β¨
π¦ 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