From 5d1a6fccb0e6d5c0930d01ae4d7f6433d844a25e Mon Sep 17 00:00:00 2001 From: Lars Dieckow Date: Thu, 7 Mar 2013 14:34:52 +0100 Subject: [PATCH] 1.000 --- .gitignore | 41 +++++++ Build.PL | 24 ++++ Changes | 9 ++ MANIFEST.SKIP | 63 +++++++++++ README | 19 ++++ lib/Sipwise/Base.pm | 98 +++++++++++++++++ lib/Sipwise/Boilerplate.pm | 193 +++++++++++++++++++++++++++++++++ lib/Sipwise/CodingStandards.pm | 74 +++++++++++++ share/.perlcriticrc | 54 +++++++++ share/.perltidyrc | 15 +++ t/MethodSignatures.pm | 7 ++ t/StrictSubs.pm | 3 + t/StrictVars.pm | 3 + t/Types.pm | 5 + t/compile.t | 5 + t/exports.t | 50 +++++++++ 16 files changed, 663 insertions(+) create mode 100644 .gitignore create mode 100644 Build.PL create mode 100644 Changes create mode 100644 MANIFEST.SKIP create mode 100644 README create mode 100644 lib/Sipwise/Base.pm create mode 100644 lib/Sipwise/Boilerplate.pm create mode 100644 lib/Sipwise/CodingStandards.pm create mode 100644 share/.perlcriticrc create mode 100644 share/.perltidyrc create mode 100644 t/MethodSignatures.pm create mode 100644 t/StrictSubs.pm create mode 100644 t/StrictVars.pm create mode 100644 t/Types.pm create mode 100644 t/compile.t create mode 100644 t/exports.t diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0f3b51e --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +RCS +CVS +SCCS +,v +.svn +.git +_darcs +.cvsignore +Descrip.MMS +DESCRIP.MMS +descrip.mms +MANIFEST +MANIFEST.bak +Makefile +blib +MakeMaker-* +pm_to_blib.ts +pm_to_blib +blibdirs.ts +Build +_build +Build.bat +Build.COM +BUILD.COM +build.com +*~ +*.old +*# +*.# +*.bak +*.tmp +*.rej +*.swp +.DS_Store +._* +cover_db +covered +META.* +MYMETA.* +SIGNATURE +Sipwise-Base-* diff --git a/Build.PL b/Build.PL new file mode 100644 index 0000000..42e078b --- /dev/null +++ b/Build.PL @@ -0,0 +1,24 @@ +use Module::Build qw(); +my $builder = Module::Build->new( + module_name => 'Sipwise-Base', + license => 'restrictive', + dist_author => 'Lars Dieckow ', + dist_version_from => 'lib/Sipwise/Base.pm', + build_requires => { + 'Test::More' => '0.88', + }, + requires => { + 'autodie' => 0, + 'lambda' => 0, + 'Module::Runtime' => 0, + 'Moose' => 2, + 'MooseX::Method::Signatures' => 0, + 'parent' => 0, + 'perl5i::2' => 0, + 'strictures' => 1, + 'TryCatch' => 0, + 'utf8' => 0, + }, + add_to_cleanup => ['Sipwise-Base-*'], +); +$builder->create_build_script; diff --git a/Changes b/Changes new file mode 100644 index 0000000..f484566 --- /dev/null +++ b/Changes @@ -0,0 +1,9 @@ +=encoding UTF-8 + +=head1 NAME + +Changes - Revision history for Sipwise-Base + +=head2 1.000 2013-03-21 + +Initial release. diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..475d6d3 --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,63 @@ +# Avoid version control files. +\bRCS(?!\.pm)\b +\bCVS(?!\.pm)\b +\bSCCS(?!\.pm)\b +,v$ +\B\.svn\b +\B\.git\b +\B\.gitignore\b +\b_darcs\b +\B\.cvsignore$ + +# Avoid VMS specific MakeMaker generated files +\bDescrip.MMS$ +\bDESCRIP.MMS$ +\bdescrip.mms$ + +# Avoid Makemaker generated and utility files. +\bMANIFEST\.bak +\bMakefile$ +\bblib/ +\bMakeMaker-\d +\bpm_to_blib\.ts$ +\bpm_to_blib$ +\bblibdirs\.ts$ # 6.18 through 6.25 generated this + +# Avoid Module::Build generated and utility files. +\bBuild$ +\b_build/ +\bBuild.bat$ +\bBuild.COM$ +\bBUILD.COM$ +\bbuild.com$ +^MANIFEST\.SKIP + +# Avoid temp and backup files. +~$ +\.old$ +\#$ +\b\.# +\.bak$ +\.tmp$ +\.# +\.rej$ +\..*\.sw.?$ + +# Avoid OS-specific files/dirs +# Mac OSX metadata +\B\.DS_Store +# Mac OSX SMB mount metadata files +\B\._ + +# Avoid Devel::Cover and Devel::CoverX::Covered files. +\bcover_db\b +\bcovered\b + +# Avoid prove files +\B\.prove$ + +# Avoid configuration metadata file +^MYMETA\. + +# Avoid archives of this distribution +\bSipwise-Base-[\d\.\_]+ diff --git a/README b/README new file mode 100644 index 0000000..49f4634 --- /dev/null +++ b/README @@ -0,0 +1,19 @@ +=encoding UTF-8 + +Sipwise-Base version 1.000 + +=head1 NAME + +README - basic information for users prior to downloading + +=head1 INSTALLATION + +See L. + +=head1 DEPENDENCIES + +See distribution meta file. + +=head1 LICENCE + +restricted diff --git a/lib/Sipwise/Base.pm b/lib/Sipwise/Base.pm new file mode 100644 index 0000000..4705edf --- /dev/null +++ b/lib/Sipwise/Base.pm @@ -0,0 +1,98 @@ +package Sipwise::Base; +use utf8; +use Module::Runtime qw(require_module); +use parent 'autodie'; +our $VERSION = '1.000'; + +sub import { + my ($class) = @_; + my $caller = caller; + + require_module('strictures'); + strictures->import(1); + + require_module('perl5i::2'); + perl5i::2->import(-skip => [qw(Signatures Try::Tiny)]); + + eval <<""; +package $caller; +use lambda 'λ'; +use perl5i::2 -skip => [qw(Signatures Try::Tiny)]; +use Moose qw(extends has with); +use MooseX::Method::Signatures; +use TryCatch; + + @_ = ($class, ':all'); + goto &autodie::import; +} + +1; + +__END__ + +=encoding UTF-8 + +=head1 NAME + +Sipwise::Base - import boilerplate code + +=head1 VERSION + +This document describes Sipwise::Base version 1.000 + +=head1 SYNOPSIS + + use Sipwise::Base; + +=head1 DESCRIPTION + +The purpose of this module is to reduce the amount of boilerplate code and to enable some Perl features that are not +available by default. This is in the spirit of +L. + +Switches on the functionality of the pragmatic modules L, L, L, L, +L, L. + +=head1 INTERFACE + +=head2 C + +See L. + +=head2 Exports + +=head1 DIAGNOSTICS + +None. + +=head1 CONFIGURATION AND ENVIRONMENT + +Sipwise::Base requires no configuration files or environment variables. + +=head1 DEPENDENCIES + +See meta file in the source distribution. + +=head1 INCOMPATIBILITIES + +None reported. + +=head1 BUGS AND LIMITATIONS + +L + +=head1 TO DO + +different profiles for command-line applications + +=head1 SEE ALSO + +L, L, Ingy's L, L + +=head1 AUTHOR + +Lars Dieckow C<< >> + +=head1 LICENCE + +restricted diff --git a/lib/Sipwise/Boilerplate.pm b/lib/Sipwise/Boilerplate.pm new file mode 100644 index 0000000..cb60d58 --- /dev/null +++ b/lib/Sipwise/Boilerplate.pm @@ -0,0 +1,193 @@ +package Sipwise::Boilerplate; +use Sipwise::Base; +our $VERSION = '1.000'; + +__END__ + +=encoding UTF-8 + +=head1 NAME + +Sipwise::Boilerplate - a template for new code + +=head1 SYNOPSIS + +Copy the following text, outdent it, save to a new file, then fill it in. Delete the C<=for author> POD sections after +you are done with them. + + package Something::Or::Other; + use Sipwise::Base; + use namespace::sweep; + + our $VERSION = '1.000'; + + … # attributes, methods, package-level code go here + + $CLASS->meta->make_immutable; + + __END__ + + =encoding UTF-8 + + =head1 NAME + + Something::Or::Other - [One line description of module's purpose here] + + =head1 VERSION + + This document describes Something::Or::Other version 1.000 + + =head1 SYNOPSIS + + use Something::Or::Other qw(); + + =for author to fill in: + Brief code example(s) here showing commonest usage(s). + This section will be as far as many users bother reading + so make it as educational and exeplary as possible. + + =head1 DESCRIPTION + + =for author to fill in: + Write a full description of the module and its features here. + Use subsections (=head2, =head3) as appropriate. + + =head1 INTERFACE + + =for author to fill in: + Write a separate section listing the public components of the modules + interface. These normally consist of either subroutines that may be + exported, or methods that may be called on objects belonging to the + classes provided by the module. + + =head2 Composition + + Something::Or::Other + ISA Something + DOES OtherRole + + All methods and attributes not mentioned here are + inherited from L or mixed in from L. + + =head2 Attributes + + =head3 C + + Type C, B attribute, designates the fnarg fnord. + + =head3 C + + Type C, whether foo is encoded into fnord. + + =head2 Methods + + =head3 C + + Returns the bar fnord as string. + + =head3 C + + $soo->mogrify; # use defaults + $soo->mogrify({blah => 42, harbl => 23}); + + Uses the supplied arguments to blah blah. + + =head4 C argument keys + + … + + =head2 Exports + + =head3 C + + Exported on demand, same as calling the default constructor followed by the L method. + + =head1 DIAGNOSTICS + + None. + + =for author to fill in: + List every single error and warning message that the module can + generate (even the ones that will "never happen"), with a full + explanation of each problem, one or more likely causes, and any + suggested remedies. + + =over + + =item C<< Error message here, perhaps with %s placeholders >> + + [Description of error here] + + =item C<< Another error message here >> + + [Description of error here] + + [Et cetera, et cetera] + + =back + + =head1 CONFIGURATION AND ENVIRONMENT + + Something::Or::Other requires no configuration files or environment variables. + + =for author to fill in: + A full explanation of any configuration system(s) used by the + module, including the names and locations of any configuration + files, and the meaning of any environment variables or properties + that can be set. These descriptions must also include details of any + configuration language used. + + =head1 DEPENDENCIES + + See meta file in the source distribution. + + =for author to fill in: + A list of all the other modules that this module relies upon, + including any restrictions on versions, and an indication whether + the module is part of the standard Perl distribution, part of the + module's distribution, or must be installed separately. + + =head1 INCOMPATIBILITIES + + None reported. + + =for author to fill in: + A list of any modules that this module cannot be used in conjunction + with. This may be due to name conflicts in the interface, or + competition for system or program resources, or due to internal + limitations of Perl (for example, many modules that use source code + filters are mutually incompatible). + + =head1 BUGS AND LIMITATIONS + + L + + No known limitations. + + =for author to fill in: + A list of known problems with the module, together with some + indication whether they are likely to be fixed in an upcoming + release. Also a list of restrictions on the features the module + does provide: data types that cannot be handled, performance issues + and the circumstances in which they may arise, practical + limitations on the size of data sets, special cases that are not + (yet) handled, etc. + + =head1 TO DO + + =for author to fill in: + future plans and ideas + + =head1 SEE ALSO + + =for author to fill in: + related work and modules, perhaps with some prose describing the + different advantages of each under which circumstances + + =head1 AUTHOR + + Your Name C<< >> + + =head1 LICENCE + + restricted diff --git a/lib/Sipwise/CodingStandards.pm b/lib/Sipwise/CodingStandards.pm new file mode 100644 index 0000000..fa250b2 --- /dev/null +++ b/lib/Sipwise/CodingStandards.pm @@ -0,0 +1,74 @@ +package Sipwise::CodingStandards; +use Sipwise::Base; +our $VERSION = '1.000'; + +__END__ + +=encoding UTF-8 + +=head1 NAME + +Sipwise::CodingStandards - Sipwise Perl coding standards + +=head1 VERSION + +This document describes Sipwise::CodingStandards version 1.000 + +=head1 DESCRIPTION + +This document outlines the coding standards for new Perl projects. Their purpose is to guide programmers to a common +code style and practices, making decisions so you don't have to. Follow them unless you have a good reason not to. See +L for the rationale. Taking Perl's philosophy to heart, the +standards are not enforced – it's up to the programmer to use common sense and sound judgement in applying them. + +The standards are not set in stone, either. If you notice that consistently I following them produces better +results, please communicate the matter and get this document ameliorated. + +=head2 common modules + +L is a module that simply bundles common other modules that you are very likely to include in a class +file - one line is enough to load all of them. The goal is to enable modern Perl programming and restrict some legacy +features of the language that should not be used anymore in new code. + +=head2 sample code template + +See L in this distribution. + +This template is derived from L for the most part. + +=head2 C + +See F in this distribution. + +L sometimes produces not optimal results with immediately nested pairs of types of brackets. + + $resultset->find({ + foo => 123, + }, + { + bar_id => 23, + quux_id => {-ident => 'baz_id'}, + }, + ); + +It is okay to manually fix this for symmetry. + + $resultset->find( + { + foo => 123, + }, + { + bar_id => 23, + quux_id => {-ident => 'baz_id'}, + }, + ); + +=head2 C + +See F in this distribution. + +Install L and L. + +=head1 AUTHOR + +C<< >> diff --git a/share/.perlcriticrc b/share/.perlcriticrc new file mode 100644 index 0000000..ae349d8 --- /dev/null +++ b/share/.perlcriticrc @@ -0,0 +1,54 @@ +colour-severity-5 = dark magenta +colour-severity-4 = dark red +colour-severity-3 = dark yellow +colour-severity-2 = dark blue +colour-severity-1 = black +verbose = %f line %l col %c\n [%s] %p (%e) = %m\n %r\n + +[-ValuesAndExpressions::ProhibitAccessOfPrivateData] +# see bug http://rt.cpan.org/Public/Bug/Display.html?id=35440 + +[-Editor::RequireEmacsFileVariables] +# no one uses Emacs here + +# next policy is gone in 1.118 +# [-Miscellanea::RequireRcsKeywords] +# git says rcs keywords are a stupid idea: +# http://git.or.cz/gitwiki/GitFaq#head-4a0afe71a2bb7734777a8b0b345e0308aefdbd40 + +[-Lax::ProhibitStringyEval::ExceptForRequire] +# already covered through BuiltinFunctions::ProhibitStringyEval::allow_includes + +[Documentation::RequirePodSections] +lib_sections = NAME | VERSION | SYNOPSIS | DESCRIPTION | INTERFACE | Composition | Attributes | Methods | Exports | DIAGNOSTICS | CONFIGURATION AND ENVIRONMENT | DEPENDENCIES | INCOMPATIBILITIES | BUGS AND LIMITATIONS | TO DO | AUTHOR | SEE ALSO + +[Bangs::ProhibitCommentedOutCode] +commentedcoderegex = \$(?!Id)[A-Za-z_].*=/ +# should not trigger on the RCS variable + +[Perl::Critic::Policy::Tics::ProhibitLongLines] +hard_max = 140 +# terminal width + +[InputOutput::RequireCheckedSyscalls] +functions = :builtins +exclude_functions = print + +[Documentation::PodSpelling] +spell_command = aspell list -l en + +[Modules::RequireExplicitInclusion] +exempt_packages = /XML::LibXML::.*/ + +[BuiltinFunctions::ProhibitStringyEval] +allow_includes = 0 +# use Module::Runtime for includes + +[-CodeLayout::ProhibitHashBarewords] +# meh, it's super annoying + +[TestingAndDebugging::RequireUseStrict] +equivalent_modules = strictures + +[TestingAndDebugging::RequireUseWarnings] +equivalent_modules = strictures diff --git a/share/.perltidyrc b/share/.perltidyrc new file mode 100644 index 0000000..80c7394 --- /dev/null +++ b/share/.perltidyrc @@ -0,0 +1,15 @@ +--block-brace-tightness=2 +--brace-tightness=2 +--break-before-all-operators +--cuddled-else +--maximum-line-length=140 +--no-opening-sub-brace-on-new-line +--no-outdent-long-quotes +--no-space-for-semicolon +--opening-brace-always-on-right +--outdent-long-comments +--paren-tightness=2 +--square-bracket-tightness=2 +--stack-closing-tokens +--stack-opening-tokens +--standard-error-output diff --git a/t/MethodSignatures.pm b/t/MethodSignatures.pm new file mode 100644 index 0000000..3acaa74 --- /dev/null +++ b/t/MethodSignatures.pm @@ -0,0 +1,7 @@ +package MethodSignatures; +use Sipwise::Base; +use t::Types 'Place'; + +method greet(Place $who) { + return "Hello, $who!"; +} diff --git a/t/StrictSubs.pm b/t/StrictSubs.pm new file mode 100644 index 0000000..9efeece --- /dev/null +++ b/t/StrictSubs.pm @@ -0,0 +1,3 @@ +package StrictSubs; +use Sipwise::Base; +fnord; diff --git a/t/StrictVars.pm b/t/StrictVars.pm new file mode 100644 index 0000000..2ad5696 --- /dev/null +++ b/t/StrictVars.pm @@ -0,0 +1,3 @@ +package StrictVars; +use Sipwise::Base; +$fnord; diff --git a/t/Types.pm b/t/Types.pm new file mode 100644 index 0000000..3165f27 --- /dev/null +++ b/t/Types.pm @@ -0,0 +1,5 @@ +package Types; +use Sipwise::Base; +use Moose::Util::TypeConstraints qw(subtype as where); + +subtype 'Place', as 'Str', where { /world/ }; diff --git a/t/compile.t b/t/compile.t new file mode 100644 index 0000000..848b596 --- /dev/null +++ b/t/compile.t @@ -0,0 +1,5 @@ +use Sipwise::Base; +use Test::More import => [qw(done_testing pass)]; + +pass 'Testing Sipwise::Base ' . Sipwise::Base->VERSION; +done_testing; diff --git a/t/exports.t b/t/exports.t new file mode 100644 index 0000000..3f1b6cf --- /dev/null +++ b/t/exports.t @@ -0,0 +1,50 @@ +use Sipwise::Base; +use Test::More import => [qw(done_testing ok)]; + +eval 'use t::StrictVars'; +ok $@, 'strict vars'; + +eval 'use t::StrictSubs'; +ok $@, 'strict subs'; + +eval '$$foobar'; +ok $@, 'strict refs'; + +eval { my $foo = 1 + undef }; +ok $@, 'fatal warnings'; + +ok say(''), 'say syntax is available'; + +ok state $foobar = 1, 'state syntax is available'; + +eval { + given (1) { + when (1) {} + default {1} + } +}; +ok !$@, 'switch syntax is available'; + +ok(__PACKAGE__->can($_), "$_ function name is available") for qw(λ extends with has method list); + +eval 'use t::MethodSignatures'; +try { + MethodSignatures->new->greet(123); +} catch($e) { + ok $e =~ /^Validation failed/; +} + +ok MethodSignatures->new->greet('world') eq 'Hello, world!', 'method signatures'; + +eval { unlink '/tmp/doesnotexist' }; +ok $@, 'autodie is in effect'; + +ok 2->pow(8), 'autobox is in effect'; + +try { + die bless { fnord => 42 } => 'Foobar'; +} catch (Foobar $e) { + ok $e->isa('Foobar'), 'TryCatch works'; +} + +done_testing;