Permalink
Browse files

Initial import

  • Loading branch information...
0 parents commit 6272e6683bea058c0d54f48d11d43a993ee9bf52 @gfx committed Dec 15, 2009
Showing with 457 additions and 0 deletions.
  1. +22 −0 .gitignore
  2. +7 −0 .shipit
  3. +4 −0 Changes
  4. +86 −0 Keyword-Boolean.xs
  5. +82 −0 MANIFEST.SKIP
  6. +27 −0 Makefile.PL
  7. +27 −0 README
  8. +68 −0 lib/Keyword/Boolean.pm
  9. +9 −0 t/00_load.t
  10. +52 −0 t/01_basic.t
  11. +30 −0 t/02_edge_cases.t
  12. +18 −0 xt/01_podspell.t
  13. +9 −0 xt/02_pod.t
  14. +10 −0 xt/03_pod-coverage.t
  15. +6 −0 xt/04_synopsis.t
22 .gitignore
@@ -0,0 +1,22 @@
+Keyword-Boolean-*
+.*
+!.gitignore
+!.shipit
+*.o
+*.obj
+*.bs
+*.def
+Makefile*
+!Makefile.PL
+*blib
+META.yml
+inc/
+MANIFEST
+*.out
+*.bak
+ppport.h
+nytprof*
+cover_db*
+*.gcda
+*.gno
+*.gcov
7 .shipit
@@ -0,0 +1,7 @@
+# auto-generated shipit config file.
+steps = FindVersion, ChangeAllVersions, CheckVersionsMatch, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN
+
+git.tagpattern = %v
+git.push_to = origin
+
+CheckChangeLog.files = Changes
4 Changes
@@ -0,0 +1,4 @@
+Revision history for Perl extension Keyword::Boolean
+
+0.001 Mon Dec 14 09:26:53 2009
+ - original version; created by Module::Setup
86 Keyword-Boolean.xs
@@ -0,0 +1,86 @@
+#define PERL_NO_GET_CONTEXT
+#include <EXTERN.h>
+#include <perl.h>
+#include <XSUB.h>
+
+#ifdef USE_PPPORT
+#include "ppport.h"
+#endif
+
+SV* hintkey_sv;
+static Perl_keyword_plugin_t next_keyword_plugin;
+
+#define keyword_active(hintkey) THX_keyword_active(aTHX_ hintkey)
+static int
+THX_keyword_active(pTHX_ SV* const hintkey)
+{
+ if(GvHV(PL_hintgv) && PL_hints & HINT_LOCALIZE_HH){
+ HE* const he = hv_fetch_ent(GvHV(PL_hintgv),
+ hintkey, FALSE, 0U);
+
+ return he && SvTRUE(HeVAL(he));
+ }
+
+ return FALSE;
+}
+
+#define keyword_enable(hintkey) THX_keyword_enable(aTHX_ hintkey)
+static void
+THX_keyword_enable(pTHX_ SV* const hintkey)
+{
+ HE* const he = hv_fetch_ent(GvHVn(PL_hintgv), hintkey, TRUE, 0U);
+ sv_setsv_mg(HeVAL(he), &PL_sv_yes);
+
+ PL_hints |= HINT_LOCALIZE_HH;
+}
+
+#define keyword_disable(hintkey) THX_keyword_disable(aTHX_ hintkey)
+static void
+THX_keyword_disable(pTHX_ SV* hintkey)
+{
+ if(!GvHV(PL_hintgv)) {
+ return;
+ }
+ hv_delete_ent(GvHV(PL_hintgv), hintkey, G_DISCARD, 0U);
+
+ PL_hints |= HINT_LOCALIZE_HH;
+}
+
+#define keyword_eq(kp, kl, s) ((kl) == (sizeof(s)-1) && strnEQ((kp), s, kl))
+
+static int
+my_keyword_plugin(pTHX_
+ char* const keyword_ptr, STRLEN const keyword_len, OP** const op_ptr)
+{
+ if(keyword_active(hintkey_sv)){
+ //warn("[%*s]", (int)keyword_len, keyword_ptr);
+ if(keyword_eq(keyword_ptr, keyword_len, "true")){
+ *op_ptr = newSVOP(OP_CONST, 0, &PL_sv_yes);
+ return KEYWORD_PLUGIN_EXPR;
+ }
+ else if(keyword_eq(keyword_ptr, keyword_len, "false")){
+ *op_ptr = newSVOP(OP_CONST, 0, &PL_sv_no);
+ return KEYWORD_PLUGIN_EXPR;
+ }
+ }
+
+ return next_keyword_plugin(aTHX_
+ keyword_ptr, keyword_len, op_ptr);
+}
+
+MODULE = Keyword::Boolean PACKAGE = Keyword::Boolean
+
+BOOT:
+ hintkey_sv = newSVpvs_share("Keyword::Boolean");
+ next_keyword_plugin = PL_keyword_plugin;
+ PL_keyword_plugin = my_keyword_plugin;
+
+void
+import(classname, ...)
+CODE:
+ keyword_enable(hintkey_sv);
+
+void
+unimport(classname, ...)
+CODE:
+ keyword_disable(hintkey_sv);
82 MANIFEST.SKIP
@@ -0,0 +1,82 @@
+
+#!start included /usr/local/bleadperl/lib/5.11.2/ExtUtils/MANIFEST.SKIP
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+\bSCCS\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$
+
+# Avoid temp and backup files.
+~$
+\.old$
+\#$
+\b\.#
+\.bak$
+\.tmp$
+\.#
+\.rej$
+
+# Avoid OS-specific files/dirs
+# Mac OSX metadata
+\B\.DS_Store
+# Mac OSX SMB mount metadata files
+\B\._
+
+# Avoid Devel::Cover files.
+\bcover_db\b
+#!end included /usr/local/bleadperl/lib/5.11.2/ExtUtils/MANIFEST.SKIP
+
+
+# skip dot files
+^\.
+
+# skip author's files
+\bauthor\b
+
+# skip object files
+Boolean\.c$
+\.o(?:bj)?$
+\.bs$
+\.def$
+
+\.out$
+
+# skip devel-cover stuff
+\.gcda$
+\.gcno$
+\.gcov$
+cover_db/
+
+# skip nytprof stuff
+nytprof/
+\.out$
+
+Keyword-Boolean-
+ppport\.h$
27 Makefile.PL
@@ -0,0 +1,27 @@
+use strict;
+use warnings;
+use inc::Module::Install;
+
+all_from 'lib/Keyword/Boolean.pm';
+
+use_ppport 3.19;
+cc_warnings;
+
+# requires ...
+
+test_requires 'Test::More' => 0.88; # done_testing()
+
+tests 't/*.t', 't/*/*.t';
+author_tests 'xt';
+
+auto_set_repository() if -d '.git';
+
+clean_files qw(
+ Keyword-Boolean-* *.stackdump
+ *.gcda *.gcno *.gcov
+ nytprof *.out
+ cover_db
+);
+
+WriteAll check_nmake => 0;
+
27 README
@@ -0,0 +1,27 @@
+This is Perl module Keyword::Boolean.
+
+INSTALLATION
+
+Keyword::Boolean installation is straightforward. If your CPAN shell is set up,
+you should just be able to do
+
+ $ cpan Keyword::Boolean
+
+Download it, unpack it, then build it as per the usual:
+
+ $ perl Makefile.PL
+ $ make && make test
+
+Then install it:
+
+ $ make install
+
+DOCUMENTATION
+
+Keyword::Boolean documentation is available as in POD. So you can do:
+
+ $ perldoc Keyword::Boolean
+
+to read the documentation online with your favorite pager.
+
+Goro Fuji (gfx)
68 lib/Keyword/Boolean.pm
@@ -0,0 +1,68 @@
+package Keyword::Boolean;
+
+use 5.011_002;
+use strict;
+use warnings;
+
+our $VERSION = '0.001';
+
+use XSLoader;
+XSLoader::load(__PACKAGE__, $VERSION);
+
+1;
+__END__
+
+=head1 NAME
+
+Keyword::Boolean - The real boolean keywords
+
+=head1 VERSION
+
+This document describes Keyword::Boolean version 0.001.
+
+=head1 SYNOPSIS
+
+ use 5.11.2;
+ use Keyword::Boolean;
+
+ my $t = true;
+ my $f = false;
+
+ ...;
+
+=head1 DESCRIPTION
+
+Keyword::Boolean provides two keywords: B<true> and B<false>.
+
+They are I<real> keywords introduced by the C<PL_keyword_plugin> mechanism,
+not by keyword-like subroutines nor by source filters, so you cannot I<call>
+them as subroutines.
+
+=head1 DEPENDENCIES
+
+Perl 5.11.2 or later, and a C compiler.
+
+=head1 BUGS
+
+No bugs have been reported.
+
+Please report any bugs or feature requests to the author.
+
+=head1 SEE ALSO
+
+L<perl5112delta>
+
+L<perlapi>
+
+=head1 AUTHOR
+
+Goro Fuji (gfx) E<lt>gfuji(at)cpan.orgE<gt>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright (c) 2009, Goro Fuji (gfx). Some rights reserved.
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
9 t/00_load.t
@@ -0,0 +1,9 @@
+#!perl -w
+
+use strict;
+use Test::More tests => 1;
+
+BEGIN { use_ok 'Keyword::Boolean' }
+
+diag "Testing Keyword::Boolean/$Keyword::Boolean::VERSION";
+
52 t/01_basic.t
@@ -0,0 +1,52 @@
+#!perl -w
+use 5.11.2;
+use strict;
+use Test::More;
+
+use constant true => 0;
+use constant false => 1;
+
+{
+ use Keyword::Boolean;
+
+ ok true, 'true is true';
+ ok !false, 'false is false';
+
+ ok !(not true);
+ ok !!(not false);
+
+ if(true){
+ pass;
+ }
+ else{
+ fail;
+ }
+
+ if(false){
+ fail;
+ }
+ else{
+ pass;
+ }
+
+ eval q{true()};
+ like $@, qr/syntax error/;
+
+ eval q{false()};
+ like $@, qr/syntax error/;
+}
+
+ok !true, 'as a subroutine';
+ok false, 'as a subroutine';
+
+use Keyword::Boolean;
+
+ok true, 'as a keyword';
+ok !false, 'as a keyword';
+
+no Keyword::Boolean;
+
+ok !true, 'as a subroutine';
+ok false, 'as a subroutine';
+
+done_testing;
30 t/02_edge_cases.t
@@ -0,0 +1,30 @@
+#!perl -w
+use 5.11.2;
+use strict;
+use Test::More;
+
+{
+ package Foo;
+
+ sub true{ 10 }
+ sub false{ 20 }
+
+ package true;
+ sub x{ 100 }
+
+ package false;
+ sub x{ 200 }
+}
+
+use Keyword::Boolean;
+
+is(Foo->true, 10);
+is(Foo->false, 20);
+
+is(Foo::true, 10);
+is(Foo::false, 20);
+
+is(true::x, 100);
+is(false::x, 200);
+
+done_testing;
18 xt/01_podspell.t
@@ -0,0 +1,18 @@
+#!perl -w
+
+use strict;
+use Test::More;
+
+eval q{ use Test::Spelling };
+
+plan skip_all => q{Test::Spelling is not installed.}
+ if $@;
+
+add_stopwords(map { split /[\s\:\-]/ } <DATA>);
+$ENV{LANG} = 'C';
+all_pod_files_spelling_ok('lib');
+
+__DATA__
+Goro Fuji (gfx)
+gfuji(at)cpan.org
+Keyword::Boolean
9 xt/02_pod.t
@@ -0,0 +1,9 @@
+#!perl -w
+
+use strict;
+use Test::More;
+eval q{use Test::Pod 1.14};
+plan skip_all => 'Test::Pod 1.14 required for testing PODU'
+ if $@;
+
+all_pod_files_ok();
10 xt/03_pod-coverage.t
@@ -0,0 +1,10 @@
+#!perl -w
+
+use Test::More;
+eval q{use Test::Pod::Coverage 1.04};
+plan skip_all => 'Test::Pod::Coverage 1.04 required for testing POD coverage'
+ if $@;
+
+all_pod_coverage_ok({
+ also_private => [qw(unimport BUILD DEMOLISH)],
+});
6 xt/04_synopsis.t
@@ -0,0 +1,6 @@
+#!perl -w
+use strict;
+use Test::More;
+eval q{use Test::Synopsis};
+plan skip_all => 'Test::Synopsis required for testing' if $@;
+all_synopsis_ok();

0 comments on commit 6272e66

Please sign in to comment.