Code-Style-Kit

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "Test2::V0" : "0",
            "Test::Deep" : "0",
            "Test::Fatal" : "0",
            "Test::More" : "0.88",
            "Test::NoTabs" : "0",
            "Test::Perl::Critic" : "0",
            "Test::Pod" : "1.41",
            "Test::Pod::Coverage" : "1.08",
            "Test::Spelling" : "0.12",
            "Test::Warnings" : "0",
            "Try::Tiny" : "0",
            "Type::Params" : "0",
            "Types::Standard" : "0",
            "autobox::Camelize" : "0",
            "autobox::Core" : "0",
            "autobox::Transform" : "0",
            "experimental" : "0",
            "feature" : "0",
            "lib" : "0",
            "namespace::autoclean" : "0",
            "true" : "0"

lib/Code/Style/Kit.pm  view on Meta::CPAN


=head1 SYNOPSIS

To build a "part":

      package My::Kit::Part;
      use strict;
      use warnings;

      sub feature_trytiny_default { 1 }
      sub feature_trytiny_export_list { 'Try::Tiny' }

      1;

To build the kit:

      package My::Kit;
      use parent qw(Code::Style::Kit My::Kit::Part My::Kit::OtherPart);
      1;

To use the kit:

    package My::App;
    use My::Kit;

    # you now have Try::Tiny imported, plus whatever OtherPart did

=head1 DESCRIPTION

This package simplifies writing "code style kits". A kit (also known
as a "policy") is a module that encapsulates the common pragmas and
modules that every package in a project should use. For instance, it
might be a good idea to always C<use strict>, enable method
signatures, and C<use true>, but it's cumbersome to put that
boilerplate in every single file in your project. Now you can do that
with a single line of code.

lib/Code/Style/Kit.pm  view on Meta::CPAN


=head2 Features

A kit provides a set of "features" (like "tags" in L<< C<Exporter> >>
or "groups" in L<< C<Sub::Exporter> >>). Feature names must match
C<^\w+$>. Some features may be exported by default.

A simple example of a feature, from the synopsis:

    sub feature_trytiny_default { 1 }
    sub feature_trytiny_export_list { 'Try::Tiny' }

or, equivalently:

    sub feature_trytiny_default { 1 }
    sub feature_trytiny_export {
        my ($self, $caller) = @_;
        require Try::Tiny;
        Try::Tiny->import::into($caller);
    }

The C<feature_*_default> method says that this feature should always
be exported (unless the user explicitly asks us not to). The
C<feature_*_export_list> is a shortcut for the simple case of
re-exporting one or more entire packages. Alternatively, the
C<feature_*_export> sub provides full flexibility, when you need it.

=head2 Feature ordering

lib/Code/Style/Kit/Parts.pod  view on Meta::CPAN

useful in building your own kits.

I<NOTE>: this distribution does I<not> depend on the modules needed by
any of these parts (you may not want to use any of them), so you'll
need to explicitly depend on them in your own distributions.

=head1 PARTS

=head2 C<Common>

imports C<strict>, fatal C<warnings>, L<< C<Try::Tiny> >>, L<< C<Carp>
>>, L<< C<true> >>, L<< C<namespace::autoclean> >>, L<< C<Log::Any> >>

=head2 C<Perl516>

enables all the features of perl version 5.16 (but not C<switch>)

=head2 C<Perl526>

enables all the features of perl version 5.26, including subroutine
signatures (but not C<switch>)

lib/Code/Style/Kit/Parts/Common.pm  view on Meta::CPAN


use Import::Into;

# use strict
sub feature_strict_default { 1 }
sub feature_strict_export { strict->import() }
sub feature_strict_order { 1 }  # export this first

# try {} catch {} finally {};
sub feature_try_tiny_default { 1 }
sub feature_try_tiny_export_list { 'Try::Tiny' }

# croak, confess, etc.
sub feature_carp_default { 1 }
sub feature_carp_export_list { 'Carp' }

# No need to finish modules with 1;
sub feature_true_default { 1 }
sub feature_true_export {
    require true;
    true->import({ into => $_[1] });

lib/Code/Style/Kit/Parts/Common.pm  view on Meta::CPAN


  package My::Kit;
  use parent qw(Code::Style::Kit Code::Style::Kit::Parts::Common);
  1;

Then:

  package My::Module;
  use My::Kit;

  # you have strict, fatal warnings, Try::Tiny, Carp, true,
  # namespace::autoclean, Log::Any

=head1 DESCRIPTION

This part defines a bunch of the features, all enabled by default:

=over

=item C<strict>

imports L<< C<strict> >>

=item C<try_tiny>

imports L<< C<Try::Tiny> >>

=item C<carp>

imports L<< C<Carp> >>

=item C<true>

imports L<< C<true> >>

=item C<fatal_warnings>

t/tests/common.t  view on Meta::CPAN

use Test2::V0;
use lib 't/lib';
use TestHelper;

my $pkg = make_pkg({
    requires => [qw(Try::Tiny Carp namespace::autoclean true Log::Any)],
    parts => [qw(Common)],
    body => <<'EOBODY',
sub use_undef { 0+undef }
sub use_log { $log->info('foo') }
sub use_croak { croak 'boom' }
sub use_try { return try { die "boom\n" } catch { return $_ } }
EOBODY
});

ok(!$pkg->can('try'),'the namespace should be autocleaned');

is($pkg->use_try,"boom\n",'Try::Tiny should be imported');

eval { $pkg->use_undef };
like($@,qr{\buninitialized value\b},'warning should be fatal');

eval { $pkg->use_croak };
like($@,qr{\bboom at t/tests/common\.t\b},'Carp should be imported');

done_testing;



( run in 0.675 second using v1.01-cache-2.11-cpan-05444aca049 )