Skip to content

Commit

Permalink
Switch from tidyall to precious
Browse files Browse the repository at this point in the history
There's a lot of changes to code in lib because of applying podtidy.
  • Loading branch information
autarch committed Jan 24, 2021
1 parent 17a8aa9 commit 640d53e
Show file tree
Hide file tree
Showing 40 changed files with 358 additions and 250 deletions.
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/*\.bs
/*\.c
/*\.o
/.tidyall.d

*~
.\#*
.build
/.tidyall.d
Build.PL
Build
Specio-*
Build.PL
Debian_CPANTS.txt
MANIFEST
META.json
Expand All @@ -14,12 +17,9 @@ MYMETA.yml
Makefile
Makefile.old
README
Specio-*
\#*\#
_build
blib*
cover_db*
/*\.bs
/*\.c
/*\.o
pm_to_blib*

44 changes: 22 additions & 22 deletions .stopwords
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
API
boolification
ClassName
Coercions
coercions
de
distro
globification
inlinable
inline
isa
Kogman
LaxVersionStr
MUTC
ModuleName
MUTC
namespace
NegativeInt
NegativeNum
NegativeOrZeroInt
NegativeOrZeroNum
NonEmptySimpleStr
NonEmptyStr
Num
PARAMETERIZABLE
numification
PackageName
PARAMETERIZABLE
parameterizable
parameterization
parameterized
PayPal
PositiveInt
PositiveNum
PositiveOrZeroInt
PositiveOrZeroNum
RegexpRef
reimplementation
Rolsky
SIGNES
SPECIO
SafeIdentifier
ScalarRef
sigils
SIGNES
SimpleStr
SingleDigit
slurpy
SPECIO
Specio
Str
StrictVersionStr
Throwable
Yuval
boolification
coercions
de
distro
globification
inlinable
inline
isa
namespace
numification
parameterizable
parameterization
parameterized
reimplementation
sigils
slurpy
structurable
subtype
subtypes
Throwable
Yuval
19 changes: 19 additions & 0 deletions dev-bin/install-xt-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

set -e

TARGET="$HOME/bin"
if [ $(id -u) -eq 0 ]; then
TARGET="/usr/local/bin"
fi
echo "Installing dev tools to $TARGET"

mkdir -p $TARGET
curl --silent --location \
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |
sh

"$TARGET/ubi" --project houseabsolute/precious --in "$TARGET"
"$TARGET/ubi" --project houseabsolute/omegasort --in "$TARGET"

echo "Add $TARGET to your PATH in order to use precious for linting and tidying"
15 changes: 15 additions & 0 deletions git/hooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

status=0

PRECIOUS=$(which precious)
if [[ -z $PRECIOUS ]]; then
PRECIOUS=./bin/precious
fi

"$PRECIOUS" lint -s
if (( $? != 0 )); then
status+=1
fi

exit $status
27 changes: 27 additions & 0 deletions git/setup.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env perl

use strict;
use warnings;

use Cwd qw( abs_path );

symlink_hook('pre-commit');

sub symlink_hook {
my $hook = shift;

my $dot = ".git/hooks/$hook";
my $file = "git/hooks/$hook.sh";
my $link = "../../$file";

if ( -e $dot ) {
if ( -l $dot ) {
return if readlink $dot eq $link;
}
warn "You already have a hook at $dot!\n";
return;
}

symlink $link, $dot
or die "Could not link $dot => $link: $!";
}
71 changes: 35 additions & 36 deletions lib/Specio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,22 @@ distribution will magically make the Perl interpreter start checking a value's
type on assignment to a variable. In fact, there's no built-in way to apply a
type to a variable at all.
Instead, you can explicitly check a value against a type, and optionally
coerce values to that type.
Instead, you can explicitly check a value against a type, and optionally coerce
values to that type.
My long-term goal is to replace Moose's built-in types and L<MooseX::Types>
with this module.
=head1 WHAT IS A TYPE?
At it's core, a type is simply a constraint. A constraint is code that checks
a value and returns true or false. Most constraints are represented by
L<Specio::Constraint::Simple> objects. However, there are other type
constraint classes for specialized kinds of constraints.
At it's core, a type is simply a constraint. A constraint is code that checks a
value and returns true or false. Most constraints are represented by
L<Specio::Constraint::Simple> objects. However, there are other type constraint
classes for specialized kinds of constraints.
Types can be named or anonymous, and each type can have a parent type. A
type's constraint is optional because sometimes you may want to create a named
subtype of some existing type without adding additional constraints.
Types can be named or anonymous, and each type can have a parent type. A type's
constraint is optional because sometimes you may want to create a named subtype
of some existing type without adding additional constraints.
Constraints can be expressed either in terms of a simple subroutine reference
or in terms of an inline generator subroutine reference. The former is easier
Expand Down Expand Up @@ -134,9 +134,9 @@ The C<Undef> type only accepts C<undef>.
The C<Defined> type accepts anything I<except> C<undef>.
The C<Num> and C<Int> types are stricter about numbers than Perl
is. Specifically, they do not allow any sort of space in the number, nor do
they accept "Nan", "Inf", or "Infinity".
The C<Num> and C<Int> types are stricter about numbers than Perl is.
Specifically, they do not allow any sort of space in the number, nor do they
accept "Nan", "Inf", or "Infinity".
The C<ClassName> type constraint checks that the name is valid I<and> that the
class is loaded.
Expand All @@ -151,8 +151,8 @@ below for details.
Perl's overloading is horribly broken and doesn't make much sense at all.
However, unlike Moose, all type constraints allow overloaded objects where
they make sense.
However, unlike Moose, all type constraints allow overloaded objects where they
make sense.
For types where overloading makes sense, we explicitly check that the object
provides the type overloading we expect. We I<do not> simply try to use the
Expand Down Expand Up @@ -197,8 +197,8 @@ the parameter applies to the values (keys are never checked).
The C<Maybe> type is a special parameterized type. It allows for either
C<undef> or a value. All by itself, it is meaningless, since it is equivalent
to "Maybe of Item", which is equivalent to Item. When parameterized, it
accepts either an C<undef> or the type of its parameter.
to "Maybe of Item", which is equivalent to Item. When parameterized, it accepts
either an C<undef> or the type of its parameter.
This is useful for optional attributes or parameters. However, you're probably
better off making your code simply not pass the parameter at all This usually
Expand All @@ -219,8 +219,8 @@ not exposed to your code. To access a type, you always call C<t('TypeName')>.
This returns the named type or dies if no such type exists.
Because types are always copied on import, it's safe to create coercions on
any type. Your coercion from C<Str> to C<Int> will not be seen by any other
Because types are always copied on import, it's safe to create coercions on any
type. Your coercion from C<Str> to C<Int> will not be seen by any other
package, unless that package explicitly imports your C<Int> type.
When you import types, you import every type defined in the package you import
Expand All @@ -229,8 +229,8 @@ definition. You I<cannot> define the same type twice internally.
=head1 CREATING A TYPE LIBRARY
By default, all types created inside a package are invisible to other
packages. If you want to create a type library, you need to inherit from
By default, all types created inside a package are invisible to other packages.
If you want to create a type library, you need to inherit from
L<Specio::Exporter> package:
package MyApp::Type::Library;
Expand All @@ -246,9 +246,8 @@ L<Specio::Exporter> package:
where => sub { $_[0] =~ /foo/i },
);
Now the MyApp::Type::Library package will export a single type named
C<Foo>. It I<does not> re-export the types provided by
L<Specio::Library::Builtins>.
Now the MyApp::Type::Library package will export a single type named C<Foo>. It
I<does not> re-export the types provided by L<Specio::Library::Builtins>.
If you want to make your library re-export some other libraries types, you can
ask for this explicitly:
Expand Down Expand Up @@ -277,9 +276,9 @@ This should just work. Use a Specio type anywhere you'd specify a type.
=head1 USING SPECIO WITH L<Moo>
Using Specio with Moo is easy. You can pass Specio constraint objects as
C<isa> parameters for attributes. For coercions, simply call C<<
$type->coercion_sub >>.
Using Specio with Moo is easy. You can pass Specio constraint objects as C<isa>
parameters for attributes. For coercions, simply call C<< $type->coercion_sub
>>.
package Foo;
Expand Down Expand Up @@ -347,18 +346,18 @@ MooseX::Types, which assume that unknown names are class names.
=item * Anon types are explicit
With L<Moose> and L<MooseX::Types>, you use the same subroutine, C<subtype()>,
to declare both named and anonymous types. With Specio, you use C<declare()> for
named types and C<anon()> for anonymous types.
to declare both named and anonymous types. With Specio, you use C<declare()>
for named types and C<anon()> for anonymous types.
=item * Class and object types are separate
Moose and MooseX::Types have C<class_type> and C<duck_type>. The former type
requires an object, while the latter accepts a class name or object.
With Specio, the distinction between accepting an object versus object or
class is explicit. There are six declaration helpers, C<object_can_type>,
C<object_does_type>, C<object_isa_type>, C<any_can_type>, C<any_does_type>,
and C<any_isa_type>.
With Specio, the distinction between accepting an object versus object or class
is explicit. There are six declaration helpers, C<object_can_type>,
C<object_does_type>, C<object_isa_type>, C<any_can_type>, C<any_does_type>, and
C<any_isa_type>.
=item * Overloading support is baked in
Expand All @@ -367,8 +366,8 @@ frustrating to use in many cases.
=item * Types can either have a constraint or inline generator, not both
Moose and MooseX::Types types can be defined with a subroutine reference as
the constraint, an inline generator subroutine, or both. This is purely for
Moose and MooseX::Types types can be defined with a subroutine reference as the
constraint, an inline generator subroutine, or both. This is purely for
backwards compatibility, and it makes the internals more complicated than they
need to be.
Expand All @@ -381,8 +380,8 @@ I simply never got around to implementing this in Moose.
=item * No crazy coercion features
Moose has some bizarre (and mostly) undocumented features relating to
coercions and parameterizable types. This is a misfeature.
Moose has some bizarre (and mostly) undocumented features relating to coercions
and parameterizable types. This is a misfeature.
=back
Expand Down
22 changes: 11 additions & 11 deletions lib/Specio/Coercion.pm
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ This parameter is required.
=item * coercion => sub { ... }
A subroutine reference implementing the coercion. It will be called as a
method on the object and passed a single argument, the value to coerce.
A subroutine reference implementing the coercion. It will be called as a method
on the object and passed a single argument, the value to coerce.
It should return the new value.
Expand Down Expand Up @@ -219,9 +219,9 @@ This environment will be used when compiling the coercion as part of a
subroutine. The named variables will be captured as closures in the generated
subroutine, using L<Eval::Closure>.
It should be very rare to need to set this in the constructor. It's more
likely that a special coercion subclass would need to provide values that it
generates internally.
It should be very rare to need to set this in the constructor. It's more likely
that a special coercion subclass would need to provide values that it generates
internally.
This parameter defaults to an empty hash reference.
Expand Down Expand Up @@ -261,9 +261,9 @@ generator.
=head2 $coercion->can_be_inlined()
This returns true if the coercion has an inline generator I<and> the
constraint it is from can be inlined. This exists primarily for the benefit of
the C<inline_coercion_and_check()> method for type constraint object.
This returns true if the coercion has an inline generator I<and> the constraint
it is from can be inlined. This exists primarily for the benefit of the
C<inline_coercion_and_check()> method for type constraint object.
=head2 $coercion->inline_environment()
Expand All @@ -277,9 +277,9 @@ Returns a clone of this object.
=head2 $coercion->clone_with_new_to($new_to_type)
This returns a clone of the coercion, replacing the "to" type with a new
one. This is intended for use when the to type itself is being cloned as part
of importing that type. We need to make sure the newly cloned coercion has the
This returns a clone of the coercion, replacing the "to" type with a new one.
This is intended for use when the to type itself is being cloned as part of
importing that type. We need to make sure the newly cloned coercion has the
newly cloned type as well.
=head1 ROLES
Expand Down
4 changes: 2 additions & 2 deletions lib/Specio/Constraint/AnyCan.pm
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ This class overrides the C<message_generator> default if none is provided.
Finally, this class requires an additional parameter, C<methods>. This must be
an array reference of method names which the constraint requires. You can also
pass a single string and it will be converted to an array reference
internally.
pass a single string and it will be converted to an array reference internally.
=head2 $any_can->methods
Expand All @@ -109,3 +108,4 @@ Returns an array reference containing the methods this constraint requires.
This class does the L<Specio::Constraint::Role::IsaType>,
L<Specio::Constraint::Role::Interface>, and L<Specio::Role::Inlinable> roles.
Loading

0 comments on commit 640d53e

Please sign in to comment.