Skip to content

Commit

Permalink
Document Base changes and don't import autoclean outside of class
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrtj committed Jun 26, 2024
1 parent 95e5c7e commit a3faae8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
45 changes: 28 additions & 17 deletions lib/Kelp/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -110,24 +110,24 @@ or
use Kelp::Base -strict; # Only use strict, warnings and v5.10
# No magic
=head1 DESCRIPTION
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<Moose> when you
are perfectly fine with L<Moo> or L<Mo>, for example.
As a nice addition, our getters and constructors are quite a bit faster than
any non-XS variant of L<Moose>.
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<Moose>, which makes the core code very fast.
There is nothing more annoying than a module that forces you to use L<Moose>
when you are perfectly fine with L<Moo> or L<Mo>, 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
Expand Down Expand Up @@ -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<attr> with L<Role::Tiny>.
=head1 SEE ALSO
L<Kelp>, L<Moose>, L<Moo>, L<Mo>, L<Any::Moose>
Expand Down

0 comments on commit a3faae8

Please sign in to comment.