Call-Context-0.05/000755 000766 000024 00000000000 14612202256 014343 5ustar00felipestaff000000 000000 Call-Context-0.05/LICENSE000644 000766 000024 00000001777 14612051133 015360 0ustar00felipestaff000000 000000 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Call-Context-0.05/Changes000644 000766 000024 00000000643 14612202073 015636 0ustar00felipestaff000000 000000 Revision history for Perl module Call::Context 0.05 Wed Apr 24 2024 - Fix documentation. (Thank you, RSAVAGE!) 0.04 Tue Apr 23 2024 - (no code changes) - Switched to MIT license. - Switched README from POD to Markdown. - Removed Travis CI. 0.03 Fri Oct 26 2018 - added must_not_be_scalar() 0.02 Sat Nov 12 20:05:00 2016 - fixed docs 0.01 Sat Nov 12 17:02:00 2016 - original version Call-Context-0.05/MANIFEST000644 000766 000024 00000000455 14612202256 015500 0ustar00felipestaff000000 000000 Changes LICENSE MANIFEST Makefile.PL README.md Todo lib/Call/Context.pm t/001_load.t t/002_must_be_list.t t/003_must_not_be_scalar.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Call-Context-0.05/t/000755 000766 000024 00000000000 14612202255 014605 5ustar00felipestaff000000 000000 Call-Context-0.05/Todo000644 000766 000024 00000000071 14612050776 015201 0ustar00felipestaff000000 000000 TODO list for Perl module Call::Context - Nothing yet Call-Context-0.05/README.md000644 000766 000024 00000003224 14612202231 015614 0ustar00felipestaff000000 000000 # NAME Call::Context - Sanity-check calling context # SYNOPSIS use Call::Context; sub gives_a_list { # Will die() if the context is not list. Call::Context::must_be_list(); return (1, 2, 3); } gives_a_list(); # die()s: incorrect context (void) my $v = gives_a_list(); # die()s: incorrect context (scalar) my @list = gives_a_list(); # lives #---------------------------------------------------------------------- sub scalar_is_bad { # Will die() if the context is scalar. Call::Context::must_not_be_scalar(); return (1, 2, 3); } scalar_is_bad(); # die()s: incorrect context (void) my $v = scalar_is_bad(); # die()s: incorrect context (scalar) my @list = scalar_is_bad(); # lives # DESCRIPTION If your function only expects to return a list, then a call in some other context is, by definition, an error. The problem is that, depending on how the function is written, it may actually do something expected in testing, but then in production act differently. # FUNCTIONS ## must\_be\_list() `die()`s if the calling function is itself called outside list context. (See the SYNOPSIS for examples.) ## must\_not\_be\_scalar() `die()`s if the calling function is itself called in scalar context. (See the SYNOPSIS for examples.) # EXCEPTIONS This module throws instances of `Call::Context::X`. `Call::Context::X` is overloaded to stringify; however, to keep memory usage low, `overload` is not loaded until instantiation. # REPOSITORY https://github.com/FGasper/p5-Call-Context # LICENSE This module is licensed under the MIT License. Call-Context-0.05/META.yml000644 000766 000024 00000001142 14612202256 015612 0ustar00felipestaff000000 000000 --- abstract: 'Sanity-check calling context' author: - 'Felipe Gasper (FELIPE)' build_requires: ExtUtils::MakeMaker: '0' Test::More: '0.44' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.62, CPAN::Meta::Converter version 2.150010' license: mit meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Call-Context no_index: directory: - t - inc resources: repository: https://github.com/FGasper/p5-Call-Context.git version: '0.05' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Call-Context-0.05/lib/000755 000766 000024 00000000000 14612202255 015110 5ustar00felipestaff000000 000000 Call-Context-0.05/Makefile.PL000644 000766 000024 00000001437 14612051121 016313 0ustar00felipestaff000000 000000 use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'Call::Context', VERSION_FROM => 'lib/Call/Context.pm', # finds \$VERSION AUTHOR => 'Felipe Gasper (FELIPE)', ABSTRACT => 'Sanity-check calling context', LICENSE => 'mit', META_MERGE => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', url => 'https://github.com/FGasper/p5-Call-Context.git', web => 'https://github.com/FGasper/p5-Call-Context', }, }, }, TEST_REQUIRES => { 'Test::More' => 0.44, }, ); Call-Context-0.05/META.json000644 000766 000024 00000002147 14612202256 015770 0ustar00felipestaff000000 000000 { "abstract" : "Sanity-check calling context", "author" : [ "Felipe Gasper (FELIPE)" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.62, CPAN::Meta::Converter version 2.150010", "license" : [ "mit" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Call-Context", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "test" : { "requires" : { "Test::More" : "0.44" } } }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "url" : "https://github.com/FGasper/p5-Call-Context.git", "web" : "https://github.com/FGasper/p5-Call-Context" } }, "version" : "0.05", "x_serialization_backend" : "JSON::PP version 4.06" } Call-Context-0.05/lib/Call/000755 000766 000024 00000000000 14612202255 015763 5ustar00felipestaff000000 000000 Call-Context-0.05/lib/Call/Context.pm000644 000766 000024 00000005441 14612202224 017745 0ustar00felipestaff000000 000000 package Call::Context; =encoding utf-8 =head1 NAME Call::Context - Sanity-check calling context =head1 SYNOPSIS use Call::Context; sub gives_a_list { # Will die() if the context is not list. Call::Context::must_be_list(); return (1, 2, 3); } gives_a_list(); # die()s: incorrect context (void) my $v = gives_a_list(); # die()s: incorrect context (scalar) my @list = gives_a_list(); # lives #---------------------------------------------------------------------- sub scalar_is_bad { # Will die() if the context is scalar. Call::Context::must_not_be_scalar(); return (1, 2, 3); } scalar_is_bad(); # die()s: incorrect context (void) my $v = scalar_is_bad(); # die()s: incorrect context (scalar) my @list = scalar_is_bad(); # lives =head1 DESCRIPTION If your function only expects to return a list, then a call in some other context is, by definition, an error. The problem is that, depending on how the function is written, it may actually do something expected in testing, but then in production act differently. =head1 FUNCTIONS =head2 must_be_list() Cs if the calling function is itself called outside list context. (See the SYNOPSIS for examples.) =head2 must_not_be_scalar() Cs if the calling function is itself called in scalar context. (See the SYNOPSIS for examples.) =head1 EXCEPTIONS This module throws instances of C. C is overloaded to stringify; however, to keep memory usage low, C is not loaded until instantiation. =head1 REPOSITORY https://github.com/FGasper/p5-Call-Context =head1 LICENSE This module is licensed under the MIT License. =cut use strict; use warnings; our $VERSION = '0.05'; my $_OVERLOADED_X; sub must_be_list { return _must_be_list(0); } sub must_not_be_scalar { return if !defined( (caller 1)[5] ); return _must_be_list(1); } sub _must_be_list { return if (caller 2)[5]; #wantarray $_OVERLOADED_X ||= eval q{ package Call::Context::X; use overload ( q<""> => \\&_spew ); 1; }; die Call::Context::X->_new($_[0]); } #---------------------------------------------------------------------- package Call::Context::X; #Not to be instantiated except from Call::Context! sub _new { my ($class, $accept_void_yn) = @_; my ($sub, $ctx) = (caller 3)[3, 5]; my (undef, $cfilename, $cline, $csub) = caller 4; if ($accept_void_yn) { return bless \"$sub called in scalar context from $csub (line $cline of $cfilename)", $class; } $ctx = defined($ctx) ? 'scalar' : 'void'; return bless \"$sub called in non-list ($ctx) context from $csub (line $cline of $cfilename)", $class; } sub _spew { ${ $_[0] } } 1; Call-Context-0.05/t/003_must_not_be_scalar.t000644 000766 000024 00000001153 14612050776 021230 0ustar00felipestaff000000 000000 package t::Call::Context::must_not_be_scalar; use strict; use warnings; use Test::More; plan tests => 6; my $PKG = __PACKAGE__; use Call::Context; sub foo { Call::Context::must_not_be_scalar(); 1; } sub try { return foo(); } scalar eval { try() }; isa_ok( $@, 'Call::Context::X' ); like( "$@", qr<\Q${PKG}::foo>, 'called function is in message' ); like( "$@", qr<\Q${PKG}::try>, 'calling function is in message' ); like( "$@", qr, 'context is in message' ); eval { try() }; is( $@, q<>, 'no die() if in void context' ); () = eval { try() }; is( $@, q<>, 'no die() if in list context' ); Call-Context-0.05/t/002_must_be_list.t000644 000766 000024 00000001205 14612050776 020053 0ustar00felipestaff000000 000000 package t::Call::Context::must_be_list; use strict; use warnings; use Test::More; plan tests => 6; my $PKG = __PACKAGE__; use Call::Context; sub foo { Call::Context::must_be_list(); 1; } sub try_it { return foo(); } eval { try_it() }; isa_ok( $@, 'Call::Context::X' ); like( "$@", qr<\Q${PKG}::foo>, 'called function is in message' ); like( "$@", qr<\Q${PKG}::try>, 'calling function is in message' ); like( "$@", qr, 'context is in message (void)' ); scalar eval { try_it() }; like( "$@", qr, 'context is in message (scalar)' ); scalar eval { () = try_it() }; is( $@, q<>, 'no die() if in list context' ); Call-Context-0.05/t/001_load.t000644 000766 000024 00000000225 14612050776 016301 0ustar00felipestaff000000 000000 # -*- perl -*- # t/001_load.t - check module loading and create testing directory use Test::More tests => 1; BEGIN { use_ok( 'Call::Context' ); }