Skip to content

Commit

Permalink
Update docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kfly8 committed Aug 18, 2024
1 parent 7ec67bd commit 18c327b
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 25 deletions.
2 changes: 1 addition & 1 deletion META.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"abstract" : "Store value constraints for Data::Checks, Type::Tiny, Moose and so on.",
"abstract" : "Store constraints for Data::Checks, Type::Tiny, Moose and so on.",
"author" : [
"kobaken <[email protected]>"
],
Expand Down
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Actions Status](https://github.com/kfly8/kura/actions/workflows/test.yml/badge.svg)](https://github.com/kfly8/kura/actions) [![Coverage Status](https://img.shields.io/coveralls/kfly8/kura/main.svg?style=flat)](https://coveralls.io/r/kfly8/kura?branch=main) [![MetaCPAN Release](https://badge.fury.io/pl/kura.svg)](https://metacpan.org/release/kura)
# NAME

kura - Store value constraints for Data::Checks, Type::Tiny, Moose and so on.
kura - Store constraints for Data::Checks, Type::Tiny, Moose and so on.

# SYNOPSIS

Expand Down Expand Up @@ -38,7 +38,7 @@ ok !Qux->check('foo') && !Qux->check('bar') && !Qux->check('baz') && Qux->check

# DESCRIPTION

Kura - means "Traditional Japanese storehouse" - stores value constraints, such as [Data::Checks](https://metacpan.org/pod/Data%3A%3AChecks), [Type::Tiny](https://metacpan.org/pod/Type%3A%3ATiny), [Moose::Meta::TypeConstraint](https://metacpan.org/pod/Moose%3A%3AMeta%3A%3ATypeConstraint) and so on.
Kura - means "Traditional Japanese storehouse" - stores constraints, such as [Data::Checks](https://metacpan.org/pod/Data%3A%3AChecks), [Type::Tiny](https://metacpan.org/pod/Type%3A%3ATiny), [Moose::Meta::TypeConstraint](https://metacpan.org/pod/Moose%3A%3AMeta%3A%3ATypeConstraint) and so on.

```
Data::Checks -----------------> ********
Expand All @@ -54,7 +54,7 @@ YourFavoriteChecker ----------> ********

## Declaring a constraint

It's easy to use to store value constraints in a package:
It's easy to use to store constraints in a package:

```perl
use kura NAME => CONSTRAINT;
Expand Down Expand Up @@ -111,10 +111,31 @@ use MyFoo qw(Foo hello);
hello(); # 'Hello, World!'
```

If you would like to use other exporter class, then set `$kura::EXPORTER_CLASS`:
# Customizing

```
$kura::EXPORTER_CLASS = 'MyExporter';
## $EXPORTER\_CLASS

`$EXPORTER_CLASS` is a package name of the Exporter class, default is `Exporter`.
You can change this class by setting `$kura::EXPORTER_CLASS`.

```perl
package MyKura {
use kura ();

sub import {
my $pkg = shift;
my $caller = caller;

local $kura::EXPORTER_CLASS = 'MyExporter';
kura->import_into($caller, @_);
}
}

package MyFoo {
use MyKura Foo => sub { $_[0] eq 'foo' };
}

MyFoo->isa('MyExporter'); # true
```

# LICENSE
Expand Down
31 changes: 26 additions & 5 deletions lib/kura.pm
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ __END__
=head1 NAME
kura - Store value constraints for Data::Checks, Type::Tiny, Moose and so on.
kura - Store constraints for Data::Checks, Type::Tiny, Moose and so on.
=head1 SYNOPSIS
Expand Down Expand Up @@ -168,7 +168,7 @@ kura - Store value constraints for Data::Checks, Type::Tiny, Moose and so on.
=head1 DESCRIPTION
Kura - means "Traditional Japanese storehouse" - stores value constraints, such as L<Data::Checks>, L<Type::Tiny>, L<Moose::Meta::TypeConstraint> and so on.
Kura - means "Traditional Japanese storehouse" - stores constraints, such as L<Data::Checks>, L<Type::Tiny>, L<Moose::Meta::TypeConstraint> and so on.
Data::Checks -----------------> ********
* *
Expand All @@ -182,7 +182,7 @@ Kura - means "Traditional Japanese storehouse" - stores value constraints, such
=head2 Declaring a constraint
It's easy to use to store value constraints in a package:
It's easy to use to store constraints in a package:
use kura NAME => CONSTRAINT;
Expand Down Expand Up @@ -229,9 +229,30 @@ So, you can add other functions to C<@EXPORT_OK>:
use MyFoo qw(Foo hello);
hello(); # 'Hello, World!'
If you would like to use other exporter class, then set C<$kura::EXPORTER_CLASS>:
=head1 Customizing
$kura::EXPORTER_CLASS = 'MyExporter';
=head2 $EXPORTER_CLASS
C<$EXPORTER_CLASS> is a package name of the Exporter class, default is C<Exporter>.
You can change this class by setting C<$kura::EXPORTER_CLASS>.
package MyKura {
use kura ();
sub import {
my $pkg = shift;
my $caller = caller;
local $kura::EXPORTER_CLASS = 'MyExporter';
kura->import_into($caller, @_);
}
}
package MyFoo {
use MyKura Foo => sub { $_[0] eq 'foo' };
}
MyFoo->isa('MyExporter'); # true
=head1 LICENSE
Expand Down
9 changes: 7 additions & 2 deletions t/01-kura.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ use MyChecker;

subtest 'Test `kura` features' => sub {
subtest '`kura` import checker into caller' => sub {
use kura Foo => MyChecker->new;
use kura X => MyChecker->new;
isa_ok X, 'MyChecker';
};

subtest '`kura` with constarint and other function.' => sub {
use MyFoo qw(Foo hello);
isa_ok Foo, 'MyChecker';
is hello(), 'Hello, Foo!';
};
};

Expand Down Expand Up @@ -37,5 +43,4 @@ subtest 'Test `kura` exceptions' => sub {
};
};


done_testing;
12 changes: 1 addition & 11 deletions t/02-import_into.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,7 @@ use lib 't/lib';
use MyChecker;

subtest 'Test `import_into` method' => sub {
subtest 'Checker is imported into $target_package' => sub {
package Foo {}
my $target_package = 'Foo';

use kura ();
kura->import_into($target_package, Hello => MyChecker->new);

isa_ok Foo::Hello(), 'MyChecker';
};

subtest 'So, you can customize the import method to your taste' => sub {
subtest 'Customize the import method to your taste' => sub {
use MyKura Foo => MyChecker->new;

# MyKura customize the name of the checker
Expand Down
16 changes: 16 additions & 0 deletions t/10-integration/Exporter-Tiny.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use Test2::V0;
use Test2::Require::Module 'Exporter::Tiny', '1.006002';
use Test2::Require::Module 'Type::Tiny', '2.000000';

use lib 't/10-integration/Exporter-Tiny';

subtest 'Test `kura` with Exporter::Tiny' => sub {
use mykura Foo => sub { $_ eq 'foo' };

isa_ok __PACKAGE__, 'Exporter::Tiny';

ok !Foo->check('');
ok Foo->check('foo');
};

done_testing;
15 changes: 15 additions & 0 deletions t/10-integration/Exporter-Tiny/mykura.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package mykura;
use strict;
use warnings;

use kura ();

sub import {
my $pkg = shift;
my $caller = caller;

local $kura::EXPORTER_CLASS = 'Exporter::Tiny';
kura->import_into($caller, @_);
}

1;
13 changes: 13 additions & 0 deletions t/lib/MyFoo.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package MyFoo;

our @EXPORT_OK;
push @EXPORT_OK, qw(hello);

use lib 't/lib';
use MyChecker;

use kura Foo => MyChecker->new;

sub hello { 'Hello, Foo!' }

1;

0 comments on commit 18c327b

Please sign in to comment.