From a3faae8358823f67d03c8175d998909af74a9a7d Mon Sep 17 00:00:00 2001 From: bbrtj Date: Wed, 26 Jun 2024 19:44:13 +0200 Subject: [PATCH] Document Base changes and don't import autoclean outside of class --- Changes | 5 +++++ lib/Kelp/Base.pm | 45 ++++++++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Changes b/Changes index fd277ab..3fb5537 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Revision history for Kelp +{NEXT} + [New Interface] + - Kelp::Base no longer imports namespace::autoclean with -strict + - Kelp::Base can now be imported with -attr + 2.12 - 2024-06-26 [Changes] - Kelp::Exception->throw now also works on objects (rethrows an exception) diff --git a/lib/Kelp/Base.pm b/lib/Kelp/Base.pm index dd5fa4e..dd4cf05 100644 --- a/lib/Kelp/Base.pm +++ b/lib/Kelp/Base.pm @@ -22,21 +22,21 @@ sub import no strict 'refs'; no warnings 'redefine'; - *{"${caller}::attr"} = sub { attr($caller, @_) }; - if ($base ne '-attr') { Kelp::Util::load_package($base); push @{"${caller}::ISA"}, $base; } + + *{"${caller}::attr"} = sub { attr($caller, @_) }; + + namespace::autoclean->import( + -cleanee => $caller + ); } strict->import; warnings->import; feature->import(':5.10'); - - namespace::autoclean->import( - -cleanee => scalar(caller), - ); } sub new @@ -110,7 +110,6 @@ or use Kelp::Base -strict; # Only use strict, warnings and v5.10 # No magic - =head1 DESCRIPTION This module provides simple lazy attributes. @@ -118,16 +117,17 @@ This module provides simple lazy attributes. =head1 WHY? Some users will naturally want to ask F<"Why not use Moose/Mouse/Moo/Mo?">. The -answer is that the Kelp web framework needs lazy attributes, but the -author wanted to keep the code light and object manager agnostic. -This allows the users of the framework to choose an object manager to -their liking. - -There is nothing more annoying than a module that forces you to use L when you -are perfectly fine with L or L, for example. - -As a nice addition, our getters and constructors are quite a bit faster than -any non-XS variant of L. +answer is that the Kelp web framework needs lazy attributes, but the author +wanted to keep the code light and object manager agnostic. This allows the +users of the framework to choose an object manager to their liking. As a nice +addition, our getters and constructors are quite a bit faster than any non-XS +variant of L, which makes the core code very fast. + +There is nothing more annoying than a module that forces you to use L +when you are perfectly fine with L or L, for example. Since this +module is so minimal, you should probably switch to a full-blown OO system of +your choice when writing your application. Kelp::Base should be compatible with +it as long as it uses blessed hashes under the hood. =head1 USAGE @@ -157,6 +157,17 @@ name with a dash. say $self->readonly; # something $self->readonly("nothing"); # no change +Kelp::Base can also be imported without turning an object into a class: + + # imports strict, warnings and :5.10 + use Kelp::Base -strict; + + # imports all of the above plus attr + use Kelp::Base -attr; + +The former is useful for less boilerplate in scripts on older perls. The latter +is useful when using C with L. + =head1 SEE ALSO L, L, L, L, L