Skip to content

Commit

Permalink
ref #162 - back compatibility functions + test
Browse files Browse the repository at this point in the history
in removing AUTOLOAD we need to check that the necessary back compat
methods are still available to ensure no (or minimal) breakage. to
do this t/html_functions.t has been added that both uses the
-compile pragma and ->compile function and also checks a function
(a()) is imported into the test's namespace.

the test was run against the version of the module prior to the
removal of AUTOLOAD and then the unnecessary functions were removed
from the _all_html_tags() function in CGI.pm

bump VERSION to dev release, document Changes
  • Loading branch information
leejo committed Feb 12, 2015
1 parent 305ccd6 commit c0c8383
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 37 deletions.
28 changes: 28 additions & 0 deletions Changes
@@ -1,3 +1,31 @@
4.13_01 2015-02-12

[ RELEASE NOTES ]
- This release removes the AUTOLOAD and compile optimisations from CGI.pm
that were introduced into CGI.pm many years ago (15+?) as a response to
its large size, which meant there was a significant compile time penalty.
This essentially deprecates the -compile pragma and ->compile method (the
-compile pragma will no longer do anything, whereas the ->compile method
will raise a deprecation warning).

- This optimisation is no longer relevant and makes the code difficult to
deal with as well as making test coverage metrics incorrect. Benchmarks
show that advantages of AUTOLOAD / lazy loading / deferred compile are
less than 0.05s, which will be dwarfed by just about any meaningful code
in a cgi script. If this is an issue for you then you should look at
running CGI.pm in a persistent environment (FCGI, etc)

- To offset some of the time added by removing the AUTOLOAD functionality
the dependencies have been made runtime rather than compile time. The
POD has also been split into its own file. CGI.pm now contains around
4000 lines of code, which compared to some modules on CPAN isn't really
that much

- Although this release should be back compatible you are encouraged to
test it throughly as if you are doing anything out of the ordinary with
CGI.pm (i.e. have bugs that may have been masked by the AUTOLOAD feature)
you may see some issues. References: GH #162, GH #137.

4.13 2014-12-18

[ RELEASE NOTES ]
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -61,6 +61,7 @@ t/headers/target.t
t/headers/type.t
t/hidden.t
t/html.t
t/html_functions.t
t/http.t
t/init.t
t/init_test.txt
Expand Down
52 changes: 23 additions & 29 deletions lib/CGI.pm
Expand Up @@ -3,7 +3,7 @@ require 5.008001;
use if $] >= 5.019, 'deprecate';
use Carp 'croak';

$CGI::VERSION='4.13';
$CGI::VERSION='4.13_01';

use CGI::Util qw(rearrange rearrange_header make_attributes unescape escape expires ebcdic2ascii ascii2ebcdic);

Expand Down Expand Up @@ -822,47 +822,41 @@ sub binmode {
}

# back compatibility html tag generation functions
sub compile {
warn "->compile / -compile is DEPRECATED";
}

sub _all_html_tags {
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element
return qw/
a abbr acronym address applet area article aside audio
b base basefont bdi bdo bgsound big blink blockquote body br
canvas caption center cite code col colgroup content
data datalist dd decorator del details dfn dialog dir div dl dt
element em embed
fieldset figcaption figure font footer frame frameset
h1 h2 h3 h4 h5 h6 head hgroup hr
a abbr acronym address applet
b base basefont bdo big blink blockquote body br
caption center cite code col colgroup
dd del dfn div dl dt
em embed
fieldset font frame frameset
h1 h2 h3 h4 h5 h6 head hr
i iframe img input ins
kbd keygen
label legend li link listing
main map mark marquee menu menuitem meta meter
nav nobr noframes noscript
object ol option output
p picture plaintext pre progress
q
rp rt ruby
s samp script section select shadow small source spacer span
strike strong style sub summary sup
table tbody td template tfoot th thead time title tr track tt
kbd
label legend li
menu meta
nobr noframes noscript
object ol option
p pre
samp script small span
strike strong style sup
table tbody td tfoot th thead title tt
u ul
var video
wbr
xmp
var
/
}

foreach my $tag (
_all_html_tags(),
( map { uc( $_ ) } _all_html_tags() )
) {
foreach my $tag ( _all_html_tags() ) {
eval "sub $tag {
return _tag_func(\$tag,\@_);
}";

foreach my $start_end ( qw/ start end / ) {

my $start_end_function = "${start_end}_${tag}";

eval "sub $start_end_function {
return _tag_func(\$start_end_function,\@_);
}";
Expand Down
2 changes: 1 addition & 1 deletion lib/CGI/Carp.pm
Expand Up @@ -318,7 +318,7 @@ use File::Spec;

$main::SIG{__WARN__}=\&CGI::Carp::warn;

$CGI::Carp::VERSION = '4.13';
$CGI::Carp::VERSION = '4.13_01';
$CGI::Carp::CUSTOM_MSG = undef;
$CGI::Carp::DIE_HANDLER = undef;
$CGI::Carp::TO_BROWSER = 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/CGI/Cookie.pm
Expand Up @@ -5,7 +5,7 @@ use warnings;

use if $] >= 5.019, 'deprecate';

our $VERSION='4.13';
our $VERSION='4.13_01';

use CGI::Util qw(rearrange unescape escape);
use overload '""' => \&as_string, 'cmp' => \&compare, 'fallback' => 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/CGI/File/Temp.pm
Expand Up @@ -3,7 +3,7 @@
# you use it directly and your code breaks horribly.
package CGI::File::Temp;

$CGI::File::Temp::VERSION = '4.13';
$CGI::File::Temp::VERSION = '4.13_01';

use parent File::Temp;
use parent Fh;
Expand Down
2 changes: 1 addition & 1 deletion lib/CGI/Pretty.pm
Expand Up @@ -4,7 +4,7 @@ use strict;
use if $] >= 5.019, 'deprecate';
use CGI ();

$CGI::Pretty::VERSION = '4.13';
$CGI::Pretty::VERSION = '4.13_01';
$CGI::DefaultClass = __PACKAGE__;
$CGI::Pretty::AutoloadClass = 'CGI';
@CGI::Pretty::ISA = qw( CGI );
Expand Down
2 changes: 1 addition & 1 deletion lib/CGI/Push.pm
@@ -1,7 +1,7 @@
package CGI::Push;
use if $] >= 5.019, 'deprecate';

$CGI::Push::VERSION='4.13';
$CGI::Push::VERSION='4.13_01';
use CGI;
use CGI::Util 'rearrange';
@ISA = ('CGI');
Expand Down
2 changes: 1 addition & 1 deletion lib/CGI/Util.pm
Expand Up @@ -6,7 +6,7 @@ use if $] >= 5.019, 'deprecate';
our @EXPORT_OK = qw(rearrange rearrange_header make_attributes unescape escape
expires ebcdic2ascii ascii2ebcdic);

our $VERSION = '4.13';
our $VERSION = '4.13_01';

use constant EBCDIC => "\t" ne "\011";

Expand Down
2 changes: 1 addition & 1 deletion lib/Fh.pm
Expand Up @@ -2,6 +2,6 @@
# that the filehandle object is a Fh
package Fh;

$Fh::VERSION = '4.13';
$Fh::VERSION = '4.13_01';

1;
2 changes: 1 addition & 1 deletion t/end_form.t
Expand Up @@ -4,6 +4,6 @@ use warnings;

use Test::More tests => 2;

BEGIN { use_ok 'CGI', qw/ -compile :form / };
BEGIN { use_ok 'CGI', qw/ :form / };

is end_form() => '</form>', 'end_form()';
27 changes: 27 additions & 0 deletions t/html_functions.t
@@ -0,0 +1,27 @@
#!perl

use strict;
use warnings;

use Test::More 'no_plan';

use CGI qw/ -compile :all /;

# check html functions are imported into this namespace
# with the -compile pragma
is( a({ bar => "boz" }),"<a bar=\"boz\" />","-compile" );

my $q = CGI->new;

foreach my $tag ( $q->_all_html_tags ) {

is( $q->$tag( { bar => 'boz' } ),"<$tag bar=\"boz\" />","$tag function" );

my $start = "start_$tag";
is( $q->$start( 'foo' ),"<$tag>","$start function" );

my $end = "end_$tag";
is( $q->$end( 'foo' ),"</$tag>","$end function" );
}

ok( $q->compile,'compile' );

0 comments on commit c0c8383

Please sign in to comment.