Mason:...classes(3pm)

πŸ“¦
version 2.24 Β· 2 versions
  • 2.24 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 2.24 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

Mason::Manual::Subclasses β€” it's giving make your own custom subclasses of Mason's classes πŸ’… bestie, you're about to build your own little Mason dynasty


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so, plot twist: you can totally subclass these Mason classes for your app πŸ‘‘

Mason::CodeCache
Mason::Compilation
Mason::Component
Mason::Component::ClassMeta
Mason::Component::Import
Mason::Component::Moose
Mason::Interp
Mason::Request
Mason::Result

...and then arrange everything so Mason always reaches for your subclass instead of its default class. main character energy, honestly. 🌟

Note: if what you want is a general purpose modification to Mason that you'd use across multiple applications, you should probably create a plugin instead of a subclass. iykyk. 🧚

πŸŽ€ CREATING A SUBCLASS πŸŽ€

a subclass should look something like this:

package My::Mason::Interp;
use Moose;
extends 'Mason::Interp';

# put your modifications here

1;

so simple, so clean, no cap πŸ’–


🌸 LETTING MASON KNOW ABOUT YOUR SUBCLASSES 🌸

there are two ways to let Mason know about your subclasses: by naming convention, and by parameters to Mason->new. two options, both iconic, pick your fighter 🫢

πŸ’œ By naming convention

first, create a subclass of Mason itself:

package My::Mason;
use Moose;
extends 'Mason';

1;

and then use that in place of Mason when you construct:

my $interp = My::Mason->new();

now here's the slay part: you can place any subclasses under 'My::Mason' and they'll automatically be picked up. literally automatic. e.g.

My::Mason::Compilation
My::Mason::Interp
My::Mason::Request

⭐ By constructor parameter

orrr you can specify your subclasses via base_* parameters to Mason->new(). e.g.

my $interp = Mason->new(
     base_compilation_class => 'My::Mason::Compilation',
     base_interp_class => 'My::Mason::Interp'
     base_request_class => 'Some::Other::Mason::Request'
);

see "CUSTOM MASON CLASSES" in Mason::Interp for a complete list. go look, it's worth it πŸ“‹


🌈 SEE ALSO 🌈

  • Mason

πŸ‘‘ AUTHOR πŸ‘‘

Jonathan Swartz <swartz@pobox.com>


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. periodt. πŸŽ€


and that's the whole vibe bestie β€” this page came to you from the perl v5.34.0 docs, dated 2022-05-27, filed under Mason:...classes(3pm) in the User Contributed Perl Documentation. mwah πŸ’‹

πŸ“¦ where this page comes from