PLP

 view release on metacpan or  search on metacpan

lib/PLP/Functions.pm  view on Meta::CPAN

package PLP::Functions;

use strict;
use warnings;

use base 'Exporter';
use Carp;
use Fcntl qw(:flock);

our $VERSION = '1.01';
our @EXPORT = qw/Entity DecodeURI EncodeURI Include include PLP_END
                 EscapeHTML
                 AddCookie ReadFile WriteFile AutoURL Counter exit/;

sub Include ($) {
	no strict;
	$PLP::file = $_[0];
	$PLP::inA = 0;
	$PLP::inB = 0;
	local $@;
	eval 'package PLP::Script; no warnings; ' . PLP::source($PLP::file, 0, join ' ', (caller)[2,1]);
	if ($@) {
		PLP::Functions::exit() if $@ =~ /\cS\cT\cO\cP/;
		PLP::error($@, 1);
	}
}

sub include ($) {
	goto &Include;
}

sub exit (;$) {
	die "\cS\cT\cO\cP\n";
}

sub PLP_END (&) {
	push @PLP::END, shift;
}

sub EscapeHTML {
	@_ == 1 or croak "Unsupported parameters given to EscapeHTML";
	unshift @_, shift if defined wantarray;  # dereference if not void
	for ($_[0]) {
		defined or next;
		s/&/&/g;
		s/"/"/g;
		s/</&lt;/g;
		s/>/&gt;/g;
	}
	return $_[0];
}

sub Entity (@) {
	my $ref = defined wantarray ? [@_] : \@_;
	for (@$ref) {
		defined or next;
		eval {
			s/&/&amp;/g;
			s/"/&quot;/g;
			s/</&lt;/g;
			s/>/&gt;/g;
			s/\n/<br>\n/g;
			s/\t/&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;/g;
			s/  /&nbsp;&nbsp;/g;
		};
	}
	return defined wantarray ? (wantarray ? @$ref : "@$ref") : undef;
}

sub DecodeURI (@) {
	my $ref = defined wantarray ? [@_] : \@_;
	for (@$ref) {
		defined or next;
		eval {
			tr/+/ /;  # Browsers do tr/ /+/ - I don't care about RFCs, but
			          # I do care about real-life situations.
			s/%([0-9A-Fa-f][0-9A-Fa-f])/chr hex $1/ge;
		};
	}
	return defined wantarray ? (wantarray ? @$ref : "@$ref") : undef;
}



( run in 0.470 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )