Skip to content

Commit

Permalink
Item14237: Simplified Assert module
Browse files Browse the repository at this point in the history
Removed AssertOn/AssertOff submodules
  • Loading branch information
vrurg committed May 17, 2018
1 parent 08c44cc commit 5c764e9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 113 deletions.
52 changes: 51 additions & 1 deletion core/lib/Assert.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,57 @@ our $soft = 0;

# Easier than farting about with AUTOLOAD; pull in the implementation we want,
# either AssertOn or AssertOff
require 'Assert' . ( DEBUG ? 'On' : 'Off' ) . '.pm';
#require 'Assert' . ( DEBUG ? 'On' : 'Off' ) . '.pm';

sub _ASSERT($;$) {

# Use run-time pre-loading of the exception because otherwise it breaks
# Moo's building of exception object constructor.
Foswiki::load_package('Foswiki::Exception');
unless ( $_[0] ) {
require Carp;
my $msg = 'Assertion';
$msg .= " ($_[1])" if defined $_[1];
$msg .= " failed!\n";
if ($soft) {
Carp::cluck($msg);
}
else {
# SMELL Experimental: generate exception instead of just die.
my ( $pkg, $file, $line ) = caller;
Foswiki::Exception::ASSERT->throw(
text => $msg,
file => $file,
line => $line,
);

#Carp::confess($msg);
}
}
return;
}

sub _UNTAINTED($) {
local ( @_, $@, $^W ) = @_;
my $x;
return eval { $x = $_[0], kill 0; 1 };
}

sub _TAINT($) {
my $DIRTY = lc('x'); # Used in TAINT
return substr( $_[0] . $DIRTY, 0, length( $_[0] ) );
}

if (DEBUG) {
*ASSERT = \&_ASSERT;
*UNTAINTED = \&_UNTAINTED;
*TAINT = \&_TAINT;
}
else {
*ASSERT = sub { };
*UNTAINTED = sub { 1 };
*TAINT = sub { $_[0] };
}

=begin TML
---++ DEBUG
Expand Down
35 changes: 0 additions & 35 deletions core/lib/AssertOff.pm

This file was deleted.

77 changes: 0 additions & 77 deletions core/lib/AssertOn.pm

This file was deleted.

0 comments on commit 5c764e9

Please sign in to comment.