Skip to content

Commit

Permalink
Update the Dist::Setup version and run the code through perlcritic an…
Browse files Browse the repository at this point in the history
…d perltidy.
  • Loading branch information
mkende committed May 9, 2024
1 parent c2b8dad commit cbacf40
Show file tree
Hide file tree
Showing 19 changed files with 669 additions and 356 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos , windows]
os: [ ubuntu, windows, macos, ]
perl: [ '5.22', '5.38' ]
exclude:
# MacOS runners are very expensive, so let’s run only on the latest Perl
Expand Down Expand Up @@ -51,18 +51,26 @@ jobs:
run: |
perl -v
- name: Install aspell
if: ${{ matrix.os == 'ubuntu' }}
run: |
sudo apt-get install aspell
- name: Install Modules
if: ${{ matrix.os != 'macos' }}
run: |
cpanm -V
cpanm -v --installdeps --notest --with-configure --with-recommends --with-suggests --with-all-features .
- name: Install aspell
if: ${{ matrix.os == 'ubuntu' }}
# MacOS runners are very costly, so let’s install the minimum amount of
# dependency.
- name: Install Modules on MacOS
if: ${{ matrix.os == 'macos' }}
run: |
sudo apt-get install aspell
cpanm -V
cpanm -v --installdeps --notest --with-configure --without-recommends --without-suggests .
- name: Run tests
- name: Run tests on Linux
if: ${{ matrix.os == 'ubuntu' }}
env:
AUTOMATED_TESTING: 1
Expand All @@ -76,7 +84,7 @@ jobs:
# MacOS runners are very costly, so let’s not run the EXTENDED_TESTING
# tests, to save some cost.
- name: Run tests
- name: Run tests on MacOS
if: ${{ matrix.os == 'macos' }}
env:
AUTOMATED_TESTING: 1
Expand All @@ -102,7 +110,7 @@ jobs:
gmake
gmake test
- name: Show Errors on Ubuntu
- name: Show Errors on Linux
if: ${{ failure() && matrix.os == 'ubuntu' }}
run: |
cat /home/runner/.cpanm/work/*/build.log
Expand All @@ -114,7 +122,7 @@ jobs:
ls -l C:/Users/RUNNER~1/
cat C:/Users/runneradmin/.cpanm/work/*/build.log
- name: Show Errors on OSX
- name: Show Errors on MacOS
if: ${{ failure() && matrix.os == 'macos' }}
run: |
cat /Users/runner/.cpanm/work/*/build.log
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
/MANIFEST
/MANIFEST.bak
/blib/
/build/
/cover_db/
/local/
/pm_to_blib
/pod2htmd.tmp
/pod2html/
/temp/
/vendor/
/*.tar.gz
Expand Down
90 changes: 90 additions & 0 deletions .perlcriticrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# DO NOT EDIT! This file is written by perl_setup_dist.
# If needed, you can add content at the end of the file.

# We report any policy of level 2 or higher (there is far too much noise if we
# go down to severity 1).
severity = 2
verbose = %f:%l: %m (%p, Severity: %s).\n

# We still include some policies whose default severity is 1
include = ValuesAndExpressions::ProhibitInterpolationOfLiterals CodeLayout::ProhibitTrailingWhitespace CodeLayout::RequireTidyCode

# Signatures are nice, let’s use them.
[TestingAndDebugging::ProhibitNoWarnings]
allow = experimental::signatures

# Methods of at most 2 lines can directly use @_ without unpacking it first
# (used here for performance reasons).
[Subroutines::RequireArgUnpacking]
short_subroutine_statements = 2

[ValuesAndExpressions::ProhibitInterpolationOfLiterals]
allow_if_string_contains_single_quote = 1

# Let’s allow moderately complex regex using the default syntax.
[RegularExpressions::RequireExtendedFormatting]
minimum_regex_length_to_complain_about = 30

# And we disable some policies that don’t work well:

# This policy confuses sub prototype with signatures.
[-Subroutines::ProhibitSubroutinePrototypes]

# This policy appears to also be confused by signatures.
[-Subroutines::ProhibitManyArgs]

# In theory we want that but, when using Locale::MakeText, this policy
# complains about the %Lexicon variables declared for the localization and there
# is no easy way to exclude them except by listing them all.
# TODO: remove once https://github.com/Perl-Critic/Perl-Critic/issues/1034 is fixed.
[-Variables::ProhibitPackageVars]

# That performance issue has been fixed in Perl 5.18 and newer.
[-Modules::RequireNoMatchVarsWithUseEnglish]

# I like postfix control :-)
[-ControlStructures::ProhibitPostfixControls]

# All the sections that I want to include are there already.
[-Documentation::RequirePodSections]

# This policy has many bugs, also I think that using the topic variable can make
# the code clearer, even in place where it would not be required to use it.
[-BuiltinFunctions::ProhibitUselessTopic]

# Let’s assume the reader knows how to write regex.
[-RegularExpressions::RequireDotMatchAnything]
[-RegularExpressions::RequireLineBoundaryMatching]

# The ',' syntax is nicer than q{,} in my opinion.
[-ValuesAndExpressions::ProhibitNoisyQuotes]

# End of the template. You can add custom content below this line.

# The style of ptp is to use complex mapping everywhere...
[-BuiltinFunctions::ProhibitComplexMappings]

# Similarly, we use map in void context everywhere and sometime mutate $_.
[-BuiltinFunctions::ProhibitVoidMap]
[-ControlStructures::ProhibitMutatingListFunctions]

[ControlStructures::ProhibitCascadingIfElse]
max_elsif = 3

[ValuesAndExpressions::ProhibitMagicNumbers]
allowed_values = -1 0 1 2 3

# This is an app, not a library
[-ErrorHandling::RequireCarping]

# Stuff we just do...
[-InputOutput::RequireBriefOpen]
[-Miscellanea::ProhibitTies]
[-Modules::ProhibitMultiplePackages]
[-ValuesAndExpressions::ProhibitEmptyQuotes]
[-Variables::ProhibitPunctuationVars]

# TODO: Get rid of these exceptions, we shouldn’t do all these things.
[-Modules::ProhibitAutomaticExportation]
[-References::ProhibitDoubleSigils]
[-Subroutines::RequireFinalReturn]
66 changes: 66 additions & 0 deletions .perltidyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# DO NOT EDIT! This file is written by perl_setup_dist.
# If needed, you can add content at the end of the file.

# The reference for all the formatting options is at:
# https://metacpan.org/pod/distribution/Perl-Tidy/bin/perltidy#FORMATTING-OPTIONS

# Basic options

--character-encoding=utf8
--output-line-ending=unix

# Code indentation

--indent-columns=2
--maximum-line-length=100
# --variable-maximum-line-length
--continuation-indentation=4
--extended-continuation-indentation
--nooutdent-long-lines # Even long lines are indented.

# Whitespace

--paren-tightness=2 # no spaces inside parens.
--keyword-paren-inner-tightness=2 # no spaces inside parens even for specific keywords.
--square-bracket-tightness=2 # no spaces inside square brackets [].
--brace-tightness=2 # spaces inside braces {} when they contain more than a single tocken.
--block-brace-tightness=0 # always put spaces inside braces that contain code block.
--nospace-for-semicolon # no spaces before semicolons ; in for loops.
--nofunction-paren-vertical-alignment # Useless without the --space-function-paren option, but in any case we would not want this.
--space-prototype-paren=2 # Always put spaces before a function prototype (and, I guess, a function signature).
--logical-padding # Possibly indent the first line of a multi-line operation.
--trim-pod
--minimum-space-to-comment=2
--nowant-left-space="." # No spaces before the '.' operator.
--nowant-right-space="." # No spaces after the '.' operator.
--space-after-keyword="require defined" # Add a space between these keywords and a following openning paren.

# Comments

--ignore-side-comment-lengths # Do not break in the middle of a line of code, because of the length of a comment at the end of that line.
--closing-side-comment-interval=15 # Don’t add closing side comment for blocks of less than 15 lines.
--closing-side-comment-list="sub BEGIN END package" # Only add closing side comments for these types of blocks.
--closing-side-comment-maximum-text=30

# Line break

--cuddled-else # 'else' are on the line of the previous closing brace.
--noopening-brace-on-new-line # Opening braces on the line of their keywords (this is actually the default).
--opening-brace-always-on-right # Opening braces at the right of the line even if there isn’t enough space for it.
--opening-token-right # braces, parens, and brackets on the right after a comma.
--stack-opening-tokens # Several opening tokens are on the same lines (can be controlled per type of tokens if needed).
--comma-arrow-breakpoint=5 # Control how hash are indented. 5 is the default.
--paren-vertical-tightness-closing=3 # Break before a closing paren except in a hash constructior.
--square-bracket-vertical-tightness-closing=0 # Break before a closing square bracket.
--brace-vertical-tightness-closing=0 # Break before a closing brace.
# It might be interesting to play with -wn and -wnxl but creating a good config will probably be difficult.

# Blank line
--noblanks-before-comments # No empty lines before a comment.

# Vertical alignment
# Unfortunately we can’t control vertical alignment depending on the context. So let’s disable it for now.
# Feature request for more control: https://rt.cpan.org/Ticket/Display.html?id=136416
-novalign

# End of the template. You can add custom content below this line.
6 changes: 4 additions & 2 deletions MANIFEST.SKIP
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
^Makefile.old$
^MANIFEST\.bak$
^MANIFEST\.SKIP$
^README(\..*)?$
^blib/
^build/
^cover_db/
^cpanfile\.snapshot$
^dist_setup\.conf$
Expand All @@ -23,10 +25,10 @@
^t/001-spelling.t
^third_party/
^pm_to_blib$
^pod2htmd\.tmp$
^pod2html/
^App-PTP-[\d.]+/
^App-PTP-[\d.]+\.tar\.gz
.*\.bak

# End of the template. You can add custom content below this line.

^README\.pod
56 changes: 52 additions & 4 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use strict;
use warnings;
use ExtUtils::MakeMaker::CPANfile;


WriteMakefile(
NAME => 'App::PTP',
DISTNAME => 'App-PTP',
Expand All @@ -29,7 +28,7 @@ WriteMakefile(
# Goes with NO_MYMETA (which would provide the dynamic config).
dynamic_config => 0,
no_index => {
directory => [ 'local', 'vendor' ],
directory => [ 'local', 'vendor', 't' ],
},
resources => {
repository => {
Expand All @@ -46,13 +45,27 @@ WriteMakefile(
clean => { FILES => 'App-PTP-*' },
);

# These platforms (usually) have GNU Make by default so the syntax that we use
# for our custom targets below will work (especially to export environment
# variables).
# On other platforms, we disable the custom parts of our Makefile generation, as
# the generated Makefile would otherwise not parse correctly.
sub supported_platform {
return $^O =~ m/^(?:linux|cygwin|MSWin32)$/;
}

sub MY::postamble {
my ($self) = @_;

my @postamble;
push @postamble, ::postamble() if *::postamble{CODE};

push @postamble, <<"MAKE_FRAGMENT";
push @postamble, <<"MAKE_FRAGMENT" if supported_platform();
ALL_PM := \$(shell find lib -name "*.pm")
ALL_EXE := script/ptp
.PHONY: distupload cover critic rawcritic tidy spelling alltest clean clean_coverdb pod2html exe
distupload: distcheck disttest
\t\$(MAKE) tardist
\tcpan-upload --directory Dist-Setup \$(DISTVNAME).tar\$(SUFFIX)
Expand All @@ -68,14 +81,49 @@ rawcritic:
\tperlcritic lib script
tidy:
\tperltidy -b -bext='/' \$(shell find lib -name "*.pm") script/ptp
\tperltidy -b -bext='/' \$(ALL_PM) \$(ALL_EXE)
spelling: export EXTENDED_TESTING = 1
spelling:
\t\$(PERLRUN) t/001-spelling.t --interactive
alltest: export EXTENDED_TESTING = 1
alltest: test
clean:: clean_coverdb clean_build clean_pod2html
clean_coverdb:
\trm -fr cover_db
clean_build:
\trm -fr build
clean_pod2html:
\trm -fr pod2html
PM_HTML := \$(patsubst %.pm, pod2html/%.html, \$(ALL_PM))
EXE_HTML := \$(patsubst %, pod2html/%.html, \$(ALL_EXE))
pod2html: \$(PM_HTML) \$(EXE_HTML)
\$(PM_HTML): pod2html/%.html: %.pm
\tmkdir -p \$(shell dirname \$@)
\tpod2html --infile \$< --outfile \$@
\$(EXE_HTML): pod2html/%.html: %
\tmkdir -p \$(shell dirname \$@)
\tpod2html --infile \$< --outfile \$@
EXE_EXE := \$(patsubst %, build/%\$(EXE_EXT), \$(ALL_EXE))
exe: export PAR_VERBATIM=1
exe: build \$(EXE_EXE)
build:
\tmkdir -p build
\$(EXE_EXE): build/%\$(EXE_EXT): %
\tpp -o \$@ -cd build/pp.cache -I lib -F "PodStrip=.*\\bApp/PTP\\b(*COMMIT)(*FAIL)|.*" \$<
MAKE_FRAGMENT

return join "\n", @postamble;
Expand Down
19 changes: 0 additions & 19 deletions README.pod
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,3 @@ run the following command:

Note: if this is the first time that you run the B<cpan> command, you will be
asked to configure it. The default answer to most questions is usually fine.

=head2 DISTRIBUTION

The main development of this software is done on
L<GitHub|https://github.com/mkende/ptp>. However, it is also available on CPAN.

The following can be used only by the module maintainer on CPAN. To update the
CPAN module, remember to increment the version number and then run the following
commands:

perl Makefile.PL
make distcheck
# Optionally, to add files not in the manifest:
# make manifest
make dist

Finally, upload the F<App-PTP-I<version>.tar.gz> file that has been created
through L<PAUSE|https://pause.perl.org>, ideally putting it under an F<App-PTP>
directory.
Loading

0 comments on commit cbacf40

Please sign in to comment.