Skip to content

Commit

Permalink
Use types with stricter constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
robrwo committed Sep 25, 2014
1 parent 0ac5b85 commit e4fc395
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 54 deletions.
9 changes: 9 additions & 0 deletions Changes
@@ -1,5 +1,14 @@
Revision history for Pod-Readme

v1.0.0_04
[Documentation]
- Fixed POD errors.

[Other Changes]
- Minor internal code tweaks.

- Use types with stricter constraints.

v1.0.0_03 2014-09-24 21:14 BST
[Bug Fixes]
- The tests for the requires plugin handle non-author builds.
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -20,6 +20,7 @@ lib/Pod/Readme/Plugin.pm
lib/Pod/Readme/Plugin/changes.pm
lib/Pod/Readme/Plugin/requires.pm
lib/Pod/Readme/Plugin/version.pm
lib/Pod/Readme/Types.pm
Makefile.PL
MANIFEST
MANIFEST.SKIP
Expand Down
2 changes: 2 additions & 0 deletions Makefile.PL
Expand Up @@ -46,13 +46,15 @@ requires(
'Path::Class' => 0.33,
'Pod::Simple' => 0,
'Try::Tiny' => 0,
'Type::Tiny' => 0,
'version' => 0.77,
);

recommends(
'Pod::Simple::LaTeX' => 0,
'Pod::Man' => 0,
'Pod::Markdown' => 0,
'Type::Tiny::XS' => 0,
);

# Note: test_requires is an alias for build_requires, so we don't need
Expand Down
50 changes: 7 additions & 43 deletions README.pod
Expand Up @@ -92,6 +92,8 @@ This distribution requires the following modules:

=item * L<Try::Tiny>

=item * L<Type::Tiny>

=back

This distribution recommends the following modules:
Expand All @@ -104,45 +106,19 @@ This distribution recommends the following modules:

=item * L<Pod::Simple::LaTeX>

=item * L<Type::Tiny::XS>

=back

=head1 RECENT CHANGES

=head2 Bug Fixes

=over 4

=item *

The tests for the requires plugin handle non-author builds.

=item *

Fix for tests on some systems.

=back

=head2 Documentation

=over 4

=item *

Consistent names in POD.

=item *

Fixed typos in Changes file.

=back

=head2 Enhancements

=over 4

=item *

Show path of missing META.yml file in requires plugin.
Fixed POD errors.

=back

Expand All @@ -152,23 +128,11 @@ Show path of missing META.yml file in requires plugin.

=item *

Added hooks for author tests in Makefile.PL.

=item *

Fixed license metadata error to make CPANTS happy, and to be consistent with license in the POD.

=item *

Tests use Exporter instead of Exporter::Lite.

=item *

Tests use Test::Kit rather than Test::Most, and explicitly import the tests modules that they use.
Minor internal code tweaks.

=item *

Removed redundant prereqs from Makefile.PL.
Use types with stricter constraints.

=back

Expand Down
6 changes: 3 additions & 3 deletions lib/Pod/Readme/Filter.pm
Expand Up @@ -15,6 +15,8 @@ use Try::Tiny;

use version 0.77; our $VERSION = version->declare('v1.0.0_04');

use Pod::Readme::Types qw/ TargetName /;

=head1 NAME
Pod::Readme::Filter - Filter README from POD
Expand Down Expand Up @@ -111,11 +113,9 @@ sub _build_output_fh {
}
}

# TODO: target format names should be \w+

has target => (
is => 'ro',
isa => 'Str',
isa => TargetName,
default => 'readme',
);

Expand Down
16 changes: 12 additions & 4 deletions lib/Pod/Readme/Plugin.pm
Expand Up @@ -9,6 +9,8 @@ use Try::Tiny;

use version 0.77; our $VERSION = version->declare('v1.0.0_04');

use Pod::Readme::Types qw/ Indentation /;

=head1 NAME
Pod::Readme::Plugin - plugin role for Pod::Readme
Expand All @@ -20,16 +22,16 @@ capabilities of the module.
=head1 ATTRIBUTES
=head2 c<verbatim_indent>
=head2 C<verbatim_indent>
The number of columns to indent a verbatim paragraph.
=cut

has verbatim_indent => (
is => 'ro',
isa => 'Int',
default => 2, # TODO: a minimum of 2
isa => Indentation,
default => 2,
);

=head1 METHODS
Expand Down Expand Up @@ -129,7 +131,7 @@ sub parse_cmd_args {
}
else {
$val = 1;
if ( ($key) = ($arg =~ /^no[_-](\w+(?:[-_]\w+)*)$/) ) {
if ( ($key) = ( $arg =~ /^no[_-](\w+(?:[-_]\w+)*)$/ ) ) {
$val = 0;
}
else {
Expand Down Expand Up @@ -319,8 +321,14 @@ Be aware that changing default values of an attribute based on
arguments means that the next time a plugin method is run, the
defaults will be changed.
=head1 SEE ALSO
Custom types in L<Pod::Readme::Types> may be useful for writing
plugins.
=cut


use namespace::autoclean;

1;
4 changes: 3 additions & 1 deletion lib/Pod/Readme/Plugin/changes.pm
Expand Up @@ -8,6 +8,8 @@ use Path::Class;

use version 0.77; our $VERSION = version->declare('v1.0.0_04');

use Pod::Readme::Types qw/ HeadingLevel /;

=head1 NAME
Pod::Readme::Plugin::changes - include latest Changes in README
Expand Down Expand Up @@ -82,7 +84,7 @@ has 'changes_verbatim' => (

has 'changes_heading_level' => (
is => 'rw',
isa => 'Int', # 1..3
isa => HeadingLevel,
default => 1,
);

Expand Down
4 changes: 3 additions & 1 deletion lib/Pod/Readme/Plugin/requires.pm
Expand Up @@ -8,6 +8,8 @@ use Path::Class;

use version 0.77; our $VERSION = version->declare('v1.0.0_04');

use Pod::Readme::Types qw/ HeadingLevel /;

=head1 NAME
Pod::Readme::Plugin::requires - include requirements in README
Expand Down Expand Up @@ -88,7 +90,7 @@ has 'requires_omit_core' => (

has 'requires_heading_level' => (
is => 'rw',
isa => 'Int', # 1..3
isa => HeadingLevel,
default => 1,
);

Expand Down
4 changes: 3 additions & 1 deletion lib/Pod/Readme/Plugin/version.pm
Expand Up @@ -6,6 +6,8 @@ use ExtUtils::MakeMaker;

use version 0.77; our $VERSION = version->declare('v1.0.0_04');

use Pod::Readme::Types qw/ HeadingLevel /;

=head1 NAME
Pod::Readme::Plugin::version - include version in README
Expand Down Expand Up @@ -58,7 +60,7 @@ has 'version_title' => (

has 'version_heading_level' => (
is => 'rw',
isa => 'Int', # 1..3
isa => HeadingLevel,
default => 1,
);

Expand Down
89 changes: 89 additions & 0 deletions lib/Pod/Readme/Types.pm
@@ -0,0 +1,89 @@
package Pod::Readme::Types;

use v5.10.1;

use strict;
use warnings;

use Exporter qw/ import /;
use Type::Tiny;

use version 0.77; our $VERSION = version->declare('v1.0.0_04');

our @EXPORT_OK = qw/ Indentation HeadingLevel TargetName /;

=head1 NAME
Pod::Readme::Types - types used by Pod::Readme
=head1 SYNOPSIS
use Pod::Readme::Types qw/ Indentation /;
has verbatim_indent => (
is => 'ro',
isa => Indentation,
default => 2,
);
=head1 DESCRIPTION
This module provides types for use with the modules in L<Pod::Readme>.
It is intended for internal use, although some of these may be useful
for writing plugins (see L<Pod::Readme::Plugin>).
=head1 EXPORTS
None by default. All functions must be explicitly exported.
=head2 C<Indentation>
The indentation level used for verbatim text. Must be an integer
greater than or equal to 2.
=cut

sub Indentation {
state $type = Type::Tiny->new(
name => 'Indentation',
constraint => sub { $_ =~ /^\d+$/ && $_ >= 2 },
message => sub { 'must be an integer >= 2' },
);
return $type;
}

=head2 C<HeadingLevel>
A heading level, used for plugin headings.
Must be either 1, 2 or 3. (Note that C<=head4> is not allowed, since
some plugins use subheadings.)
=cut

sub HeadingLevel {
state $type = Type::Tiny->new(
name => 'HeadingLevel',
constraint => sub { $_ =~ /^[123]$/ },
message => sub { 'must be an integer between 1 and 3' },
);
return $type;
}

=head2 C<TargetName>
A name of a target, e.g. "readme".
=cut

sub TargetName {
state $type = Type::Tiny->new(
name => 'TargetName',
constraint => sub { $_ =~ /^\w+$/ },
message => sub { 'must be an alphanumeric string' },
);
return $type;
}

1;
10 changes: 9 additions & 1 deletion xt/namespaces.t
@@ -1,5 +1,13 @@
use strict;
use warnings;

use Test::More;
use Test::CleanNamespaces;

all_namespaces_clean;
my %skip = map { $_ => 1 } qw/ Pod::Readme::Types /;

my @modules = grep { !$skip{$_} } Test::CleanNamespaces->find_modules;

namespaces_clean(@modules);

done_testing;

0 comments on commit e4fc395

Please sign in to comment.