r44142 - in /branches/upstream/libjavascript-packer-perl: ./ current/ current/lib/ current/lib/JavaScript/ current/t/ current/t/scripts/

emhn-guest at users.alioth.debian.org emhn-guest at users.alioth.debian.org
Wed Sep 16 17:23:08 UTC 2009


Author: emhn-guest
Date: Wed Sep 16 17:23:02 2009
New Revision: 44142

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=44142
Log:
[svn-inject] Installing original source of libjavascript-packer-perl

Added:
    branches/upstream/libjavascript-packer-perl/
    branches/upstream/libjavascript-packer-perl/current/
    branches/upstream/libjavascript-packer-perl/current/Changes
    branches/upstream/libjavascript-packer-perl/current/MANIFEST
    branches/upstream/libjavascript-packer-perl/current/META.yml
    branches/upstream/libjavascript-packer-perl/current/Makefile.PL
    branches/upstream/libjavascript-packer-perl/current/README
    branches/upstream/libjavascript-packer-perl/current/lib/
    branches/upstream/libjavascript-packer-perl/current/lib/JavaScript/
    branches/upstream/libjavascript-packer-perl/current/lib/JavaScript/Packer.pm
    branches/upstream/libjavascript-packer-perl/current/t/
    branches/upstream/libjavascript-packer-perl/current/t/00-load.t
    branches/upstream/libjavascript-packer-perl/current/t/01-io.t
    branches/upstream/libjavascript-packer-perl/current/t/pod.t
    branches/upstream/libjavascript-packer-perl/current/t/scripts/
    branches/upstream/libjavascript-packer-perl/current/t/scripts/s1-expected.js
    branches/upstream/libjavascript-packer-perl/current/t/scripts/s1.js
    branches/upstream/libjavascript-packer-perl/current/t/scripts/s2-expected.js
    branches/upstream/libjavascript-packer-perl/current/t/scripts/s2.js
    branches/upstream/libjavascript-packer-perl/current/t/scripts/s3-expected.js
    branches/upstream/libjavascript-packer-perl/current/t/scripts/s3.js
    branches/upstream/libjavascript-packer-perl/current/t/scripts/s4-expected.js
    branches/upstream/libjavascript-packer-perl/current/t/scripts/s4.js
    branches/upstream/libjavascript-packer-perl/current/t/scripts/s5-expected.js
    branches/upstream/libjavascript-packer-perl/current/t/scripts/s5.js

Added: branches/upstream/libjavascript-packer-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/Changes?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/Changes (added)
+++ branches/upstream/libjavascript-packer-perl/current/Changes Wed Sep 16 17:23:02 2009
@@ -1,0 +1,24 @@
+Revision history for JavaScript-Packer
+
+0.02	2009-04-10
+	- Changed version number
+
+0.01_02	2009-03-16
+	- Bugfix
+
+0.01_01	2009-03-15
+	- Changed compression level names
+	- Added compression level 'best'
+	- Updated some regular expressions
+	- Added some tests
+	
+0.0102	2008-11-24
+	- Former changes didn't work. Undone these changes. I'm sorry
+	for that. This will not happen again.
+	- Changed requirements to perl 5.8.
+
+0.0101	2008-11-20
+	Replaced int() by sprintf() for perl 5.6
+
+0.01	2008-11-15
+	First version, released on an unsuspecting world.

Added: branches/upstream/libjavascript-packer-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/MANIFEST?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/MANIFEST (added)
+++ branches/upstream/libjavascript-packer-perl/current/MANIFEST Wed Sep 16 17:23:02 2009
@@ -1,0 +1,19 @@
+Changes
+lib/JavaScript/Packer.pm
+Makefile.PL
+MANIFEST
+README
+t/00-load.t
+t/01-io.t
+t/pod.t
+t/scripts/s1-expected.js
+t/scripts/s1.js
+t/scripts/s2-expected.js
+t/scripts/s2.js
+t/scripts/s3-expected.js
+t/scripts/s3.js
+t/scripts/s4-expected.js
+t/scripts/s4.js
+t/scripts/s5-expected.js
+t/scripts/s5.js
+META.yml                                 Module meta-data (added by MakeMaker)

Added: branches/upstream/libjavascript-packer-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/META.yml?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/META.yml (added)
+++ branches/upstream/libjavascript-packer-perl/current/META.yml Wed Sep 16 17:23:02 2009
@@ -1,0 +1,14 @@
+--- #YAML:1.0
+name:                JavaScript-Packer
+version:             0.02
+abstract:            Perl version of Dean Edwards' Packer.js
+license:             perl
+author:              
+    - Merten Falk <nevesenin at cpan.org>
+generated_by:        ExtUtils::MakeMaker version 6.42
+distribution_type:   module
+requires:     
+    Test::More:                    0
+meta-spec:
+    url:     http://module-build.sourceforge.net/META-spec-v1.3.html
+    version: 1.3

Added: branches/upstream/libjavascript-packer-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/Makefile.PL?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/Makefile.PL (added)
+++ branches/upstream/libjavascript-packer-perl/current/Makefile.PL Wed Sep 16 17:23:02 2009
@@ -1,0 +1,20 @@
+use 5.008;
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME                => 'JavaScript::Packer',
+    AUTHOR              => 'Merten Falk <nevesenin at cpan.org>',
+    VERSION_FROM        => 'lib/JavaScript/Packer.pm',
+    ABSTRACT_FROM       => 'lib/JavaScript/Packer.pm',
+    ($ExtUtils::MakeMaker::VERSION >= 6.3002
+      ? ('LICENSE'=> 'perl')
+      : ()),
+    PL_FILES            => {},
+    PREREQ_PM => {
+        'Test::More' => 0,
+    },
+    dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+    clean               => { FILES => 'JavaScript-Packer-*' },
+);

Added: branches/upstream/libjavascript-packer-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/README?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/README (added)
+++ branches/upstream/libjavascript-packer-perl/current/README Wed Sep 16 17:23:02 2009
@@ -1,0 +1,52 @@
+JavaScript-Packer
+
+The README is used to introduce the module and provide instructions on
+how to install the module, any machine dependencies it may have (for
+example C compilers and installed libraries) and any other information
+that should be provided before the module is installed.
+
+A README file is required for CPAN modules since CPAN extracts the README
+file from a module distribution so that people browsing the archive
+can use it to get an idea of the module's uses. It is usually a good idea
+to provide version information here so that people can decide whether
+fixes for the module are worth downloading.
+
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+	perl Makefile.PL
+	make
+	make test
+	make install
+
+SUPPORT AND DOCUMENTATION
+
+After installing, you can find documentation for this module with the
+perldoc command.
+
+    perldoc JavaScript::Packer
+
+You can also look for information at:
+
+    RT, CPAN's request tracker
+        http://rt.cpan.org/NoAuth/Bugs.html?Dist=JavaScript-Packer
+
+    AnnoCPAN, Annotated CPAN documentation
+        http://annocpan.org/dist/JavaScript-Packer
+
+    CPAN Ratings
+        http://cpanratings.perl.org/d/JavaScript-Packer
+
+    Search CPAN
+        http://search.cpan.org/dist/JavaScript-Packer/
+
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2008 Merten Falk
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+

Added: branches/upstream/libjavascript-packer-perl/current/lib/JavaScript/Packer.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/lib/JavaScript/Packer.pm?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/lib/JavaScript/Packer.pm (added)
+++ branches/upstream/libjavascript-packer-perl/current/lib/JavaScript/Packer.pm Wed Sep 16 17:23:02 2009
@@ -1,0 +1,478 @@
+package JavaScript::Packer;
+
+use 5.008;
+use warnings;
+use strict;
+use Carp;
+
+use vars qw/$VERSION $COMMENT $DATA $WHITESPACE $CLEAN $BLOCK $WORD/;
+
+# =========================================================================== #
+
+$VERSION = '0.02';
+
+$WORD = qr/((?>[a-zA-Z0-9_]+))/;
+
+$BLOCK = qr/(function\s*[a-zA-Z0-9_\x24]*\s*\(\s*(([a-zA-Z0-9_\x24][a-zA-Z0-9_\x24, ]*[a-zA-Z0-9_\x24])*)\s*\)\s*)?(\{([^{}]*)\})/;
+
+$COMMENT = [
+	{
+		'regexp'	=> qr/(\/\/|;;;)[^\n]*\n?/,
+		'replacement'	=> 'sprintf( " " )'
+	},
+	{
+		'regexp'	=> qr/(\/\*[^*]*\*+([^\/][^*]*\*+)*\/)/,
+		'replacement'	=> 'sprintf( " " )'
+	}
+];
+
+$DATA = [
+	{
+		'regexp'	=> qr/\s+(\/(\\[\/\\]|[^*\/])(\\.|[^\/\n\\])*\/[gim]*)/,
+		'replacement'	=> 'sprintf( "%s", $1 )'
+	},
+	{
+		'regexp'	=> qr/([^a-zA-Z0-9_\x24\/'"*)\?:])(\/(\\[\/\\]|[^*\/])(\\.|[^\/\n\\])*\/[gim]*)/,
+		'replacement'	=> 'sprintf( "%s%s", $1, $2 )'
+	},
+	{
+		'regexp'	=> qr/"(?>(?:(?>[^"\\]+)|\\.|\\")*)"|'(?>(?:(?>[^'\\]+)|\\.|\\')*)'/,
+		'replacement'	=> '$&'
+	},
+	{
+		'regexp'	=> qr/\/\*@|@\*\/|\/\/@[^\n]*\n/,
+		'replacement'	=> '$&'
+	}
+];
+
+$WHITESPACE = [
+	{
+		'regexp'	=> qr/(\d)\s+(\.\s*[a-z\x24_\[(])/,
+		'replacement'	=> 'sprintf( "%s %s", $1, $2 )'
+	},
+	{
+		'regexp'	=> qr/([+-])\s+([+-])/,
+		'replacement'	=> 'sprintf( "%s %s", $1, $2 )'
+	},
+	{
+		'regexp'	=> qr/\b\s+(\x24)\s+\b/,
+		'replacement'	=> 'sprintf( " %s ", $1 )'
+	},
+	{
+		'regexp'	=> qr/(\x24)\s+\b/,
+		'replacement'	=> 'sprintf( "%s ", $1 )'
+	},
+	{
+		'regexp'	=> qr/\b\s+(\x24)/,
+		'replacement'	=> 'sprintf( " %s", $1 )'
+	},
+	{
+		'regexp'	=> qr/\b\s+\b/,
+		'replacement'	=> 'sprintf( " " )'
+	},
+	{
+		'regexp'	=> qr/\s+/,
+		'replacement'	=> ''
+	},
+];
+
+$CLEAN = [
+	{
+		'regexp'	=> qr/\(\s*;\s*;\s*\)/,
+		'replacement'	=> '(;;)'
+	},
+	{
+		'regexp'	=> qr/;+\s*([};])/,
+		'replacement'	=> '$1'
+	},
+];
+
+# =========================================================================== #
+
+sub minify {
+	my ( $input, $opts ) = @_;
+	
+	if ( ref( $input ) and ref( $input ) ne 'SCALAR' ) {
+		carp( 'First argument must be a scalar or scalarref!' );
+		return undef;
+	}
+	
+	my $javascript = ref( $input ) ? $input : \$input;
+	
+	if ( ref( $opts ) ne 'HASH' ) {
+		carp( 'Second argument must be a hashref of options! Using defaults!' ) if ( $opts );
+		$opts = { 'compress' => 'clean', 'copyright' => '' };
+	}
+	else {
+		$opts->{'compress'} ||= 'clean';
+		unless (
+			grep(
+				$_ eq $opts->{'compress'},
+				( 'clean', 'minify', 'shrink', 'base62', 'obfuscate', 'best' )
+			)
+		) {
+			$opts->{'compress'} = 'clean';
+		}
+		
+		if ( $opts->{'compress'} eq 'minify' ) {
+			$opts->{'compress'} = 'clean';
+		}
+		elsif ( $opts->{'compress'} eq 'base62' ) {
+			$opts->{'compress'} = 'obfuscate';
+		}
+		
+		$opts->{'copyright'}	= ( $opts->{'copyright'} and $opts->{'compress'} eq 'clean' ) ? ( '/* ' . $opts->{'copyright'} . ' */' ) : '';
+	}
+	
+	my $data	= [];
+	
+	${$javascript} =~ s/~jmv_\d+~/ /;
+	${$javascript} =~ s/~jmb_\d+~/ /;
+	
+	${$javascript} =~ s/\\\r?\n//gsm;
+	${$javascript} =~ s/\r//gsm;
+	
+	local *_store = sub {
+		my ( $regexp, $match ) = @_;
+		
+		my @match = $match =~ /$regexp->{'regexp'}/;
+		my $replacement = $regexp->{'replacement'};
+		
+		for ( my $i = 0; $i < scalar( @match ); $i++ ) {
+			my $rep_char	= $i + 1;
+			my $rep_match	= $match[$i] || '';
+			
+			$rep_match =~ s/[\/\\]/\\$&/g;
+			
+			$replacement =~ s/\$$rep_char/q\/$rep_match\//g;
+		}
+		
+		$match =~ s/[\/\\]/\\$&/g;
+		
+		$replacement =~ s/\$&/q\/$match\//g;
+		
+		my $store = eval( $replacement . ';' );
+		
+		return '' unless ( $store );
+		
+		my $ret = '~jmv_' . scalar( @{$data} ) . '~';
+		
+		if ( $store =~ /^([^'"])(\/.*)$/sm ) {
+			$ret = $1 . $ret;
+			$store = $2;
+		}
+	
+		foreach my $regexp ( @$DATA ) {
+			next unless ( $regexp->{'regexp'} and $store !~ /$regexp->{'regexp'}/ );
+			$store =~ s/$regexp->{'regexp'}/_store( $regexp, $& )/egsm;
+		}
+		
+		push( @{$data}, $store );
+		
+		return $ret;
+	};
+	
+	foreach my $regexp ( @$DATA ) {
+		next unless ( $regexp->{'regexp'} );
+		${$javascript} =~ s/$regexp->{'regexp'}/_store( $regexp, $& )/egsm;
+	}
+	
+	foreach my $regexp ( @$COMMENT ) {
+		next unless ( $regexp->{'regexp'} );
+		${$javascript} =~ s/$regexp->{'regexp'}/ /gsm;
+	}
+	
+	foreach my $regexp ( @$WHITESPACE ) {
+		next unless ( $regexp->{'regexp'} );
+		${$javascript} =~ s/$regexp->{'regexp'}/_store( $regexp, $& )/egsm;
+	}
+	
+	foreach my $regexp ( @$CLEAN ) {
+		next unless ( $regexp->{'regexp'} );
+		${$javascript} =~ s/$regexp->{'regexp'}/_store( $regexp, $& )/egsm;
+	}
+	
+	while ( ${$javascript} =~ /~jmv_(\d+)~/ ) {
+		${$javascript} =~ s/~jmv_(\d+)~/$data->[$1]/eg;
+	}
+	
+	if ( $opts->{'compress'} ne 'clean' ) {
+		my $block	= [];
+		$data		= [];
+		
+		foreach my $regexp ( @$DATA ) {
+			next unless ( $regexp->{'regexp'} );
+			${$javascript} =~ s/$regexp->{'regexp'}/_store( $regexp, $& )/egsm;
+		}
+		
+		local *_decode = sub {
+			my $match = shift;
+			
+			while ( $match =~ /~jmb_\d+~/ ) {
+				$match =~ s/~jmb_(\d+)~/$block->[$1]/eg;
+			}
+			
+			return $match;
+		};
+		
+		local *_encode = sub {
+			my $match = shift;
+			
+			my ( $func, undef, $args ) = $match =~ /$BLOCK/;
+			
+			if ( $func ) {
+				$match = _decode( $match );
+				
+				$args ||= '';
+				
+				my %block_vars = map { $_ => 1 } ( $match =~ /var\s+((?>[a-zA-Z0-9_\x24]+))/g ), split( /\s*,\s*/, $args );
+
+				local *_encode52 = sub {
+					my $c = shift;
+					
+					my $m = $c % 52;
+					
+					my $ret = $m > 25 ? chr( $m + 39 ) : chr( $m + 97 );
+					
+					if ( $c >= 52 ) {
+						$ret = _encode52( int( $c / 52 ) ) . $ret;
+					}
+					
+					return $ret;
+				};
+				
+				my $cnt = 0;
+				foreach my $block_var ( keys( %block_vars ) ) {
+					if ( length( $block_var ) > 1 ) {
+						my $short_id = _encode52( $cnt );
+						while ( $match =~ /[^a-zA-Z0-9_\x24\.]\Q$short_id\E[^a-zA-Z0-9_\x24:]/ ) {
+							$short_id = _encode52( $cnt++ );
+						}
+						$match =~ s/(?<![a-zA-Z0-9_\x24\.])\Q$block_var\E(?![a-zA-Z0-9_\x24:])/$short_id/g;
+						$match =~ s/(?<![\{,a-zA-Z0-9_\x24\.])\Q$block_var\E:/sprintf( '%s:', $short_id )/eg;
+					}
+				}
+			}
+			
+			my $ret = '~jmb_' . scalar( @{$block} ) . '~';
+			
+			push( @{$block}, $match );
+			
+			return $ret;
+		};
+		
+		while( ${$javascript} =~ /$BLOCK/ ) {
+			${$javascript} =~ s/$BLOCK/_encode( $& )/egsm;
+		}
+		
+		${$javascript} = _decode( ${$javascript} );
+		
+		while ( ${$javascript} =~ /~jmv_(\d+)~/ ) {
+			${$javascript} =~ s/~jmv_(\d+)~/$data->[$1]/egsm;
+		}
+	}
+	else {
+		${$javascript} = $opts->{'copyright'} . ${$javascript} if ( $opts->{'copyright'} );
+	}
+	
+	if ( $opts->{'compress'} eq 'obfuscate' or $opts->{'compress'} eq 'best' ) {
+		my $words = {};
+		
+		my @words = ${$javascript} =~ /$WORD/g;
+		
+		my $idx = 0;
+		
+		map {
+			if ( exists( $words->{$_} ) ) {
+				$words->{$_}->{'count'}++;
+			}
+			else {
+				$words->{$_}->{'count'} = 1;
+			}
+		} @words;
+		
+		WORD: foreach my $word ( sort { $words->{$b}->{'count'} <=> $words->{$a}->{'count'} } keys( %{$words} ) ) {
+			
+			if ( exists( $words->{$word}->{'encoded'} ) and $words->{$word}->{'encoded'} eq $word ) {
+				next WORD;
+			}
+			
+			local *_encode62 = sub {
+				my $c = shift;
+				
+				my $m = $c % 62;
+				
+				my $ret = $m > 35 ? chr( $m + 29 ) : $m > 9 ? chr( $m + 87 ) : $m;
+				
+				if ( $c >= 62 ) {
+					$ret = _encode62( int( $c / 62 ) ) . $ret;
+				}
+				
+				return $ret;
+			};
+			
+			my $encoded = _encode62( $idx );
+			
+			if ( exists( $words->{$encoded} ) ) {
+				my $next = 0;
+				if ( exists( $words->{$encoded}->{'encoded'} ) ) {
+					my %enc = %{$words->{$encoded}};
+					$words->{$word}->{'encoded'} = $words->{$encoded}->{'encoded'};
+					$words->{$word}->{'index'} = $words->{$encoded}->{'index'};
+					$words->{$word}->{'minus'} = length( $word ) - length( $words->{$word}->{'encoded'} );
+					$next = 1;
+				}
+				$words->{$encoded}->{'encoded'} = $encoded;
+				$words->{$encoded}->{'index'} = $idx;
+				$words->{$encoded}->{'minus'} = 0;
+				$idx++;
+				next WORD if ( $next );
+				redo WORD;
+			}
+			
+			$words->{$word}->{'encoded'} = $encoded;
+			$words->{$word}->{'index'} = $idx;
+			$words->{$word}->{'minus'} = length( $word ) - length( $encoded );
+			
+			$idx++;
+		}
+		
+		my $packed_length = length( ${$javascript} );
+		
+		map {
+			$packed_length -= ( $words->{$_}->{'count'} * $words->{$_}->{'minus'} );
+		} keys( %{$words} );
+		
+		my $pc = scalar( keys( %{$words} ) );
+		$packed_length += length( $pc );
+		
+		my $pa = $pc > 2 ? $pc < 62 ? $pc : 62 : 2;
+		$packed_length += length( $pa );
+		
+		my $pk = join(
+			'|',
+			map {
+				$words->{$_}->{'encoded'} ne $_ ? $_ : '';
+			} sort { 
+				$words->{$a}->{'index'} <=> $words->{$b}->{'index'}
+			} keys( %{$words} )
+		);
+		$packed_length += length( $pk );
+		
+		my $pe = 'String';
+		
+		my $pr = 'c';
+		
+		if ( $pa > 10 ) {
+			if ( $pa <= 36 ) {
+				$pe = q~function(c){return c.toString(a)}~;
+			}
+			$pr = q~e(c)~;
+		}
+		if ( $pa > 36 ) {
+			$pe = q~function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))}~;
+		}
+		$packed_length += length( $pe );
+		$packed_length += length( $pr ) * 2;
+		
+		my $f_str = q~eval(function(p,a,c,k,e,r){e=%s;if(!''.replace(/^/,String)){while(c--)r[%s]=k[c]~;
+		$f_str .= q~||%s;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.~;
+		$f_str .= q~replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('%s',%s,%s,'%s'.split('|'),0,{}))~;
+		
+		$packed_length += length( $f_str );
+		$packed_length -= ( $f_str =~ s/%s/%s/g ) * 2;
+		
+		map {
+			$packed_length -= length( $_ ) - 3;
+		} ${$javascript} =~ s/((?>[\r\n]+))/$1/g;
+		
+		$packed_length += ${$javascript} =~ tr/\\\'/\\\'/;
+		
+		if ( $opts->{'compress'} eq 'obfuscate' or $packed_length <= length( ${$javascript} ) ) {
+		
+			${$javascript} =~ s/$WORD/sprintf( "%s", $words->{$1}->{'encoded'} )/eg;
+			
+			${$javascript}	=~ s/([\\'])/\\$1/g;
+			${$javascript}	=~ s/[\r\n]+/\\n/g;
+			
+			my $pp = ${$javascript};
+			
+			${$javascript} = sprintf( $f_str, $pe, $pr, $pr, $pp, $pa, $pc, $pk );
+		}
+	}
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+JavaScript::Packer - Perl version of Dean Edwards' Packer.js
+
+=head1 VERSION
+
+Version 0.02
+
+=cut
+
+=head1 SYNOPSIS
+
+A JavaScript Compressor
+
+This module does exactly the same as Dean Edwards' Packer.js
+
+Take a look at http://dean.edwards.name/packer/
+
+use JavaScript::Packer;
+
+JavaScript::Packer::minify( $javascript, $opts );
+
+First argument must be a scalarref of JavaScript-Code.
+Second argument must be a hashref of options. Possible options are
+
+=over 4
+
+=item compress
+
+Defines compression level. Possible values are 'clean', 'shrink',
+'obfuscate' and 'best'.
+Default value is 'clean'.
+'best' uses 'shrink' or 'obfuscate' depending on which result is shorter. This is
+because short scripts will grow if compression level is 'obfuscate'.
+
+For backward compatibility 'minify' and 'base62' will still work.
+
+=item copyright
+
+You can add a copyright notice on top of the script. The copyright notice will
+only be added if the compression value is 'clean'.
+
+=back
+
+=head1 AUTHOR
+
+Merten Falk, C<< <nevesenin at cpan.org> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to C<bug-javascript-packer at rt.cpan.org>, or through
+the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=JavaScript-Packer>.  I will be notified, and then you'll
+automatically be notified of progress on your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+perldoc JavaScript::Packer
+
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2009 Merten Falk, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+
+=cut

Added: branches/upstream/libjavascript-packer-perl/current/t/00-load.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/00-load.t?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/00-load.t (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/00-load.t Wed Sep 16 17:23:02 2009
@@ -1,0 +1,9 @@
+#!perl -T
+
+use Test::More tests => 1;
+
+BEGIN {
+	use_ok( 'JavaScript::Packer' );
+}
+
+diag( "Testing JavaScript::Packer $JavaScript::Packer::VERSION, Perl $], $^X" );

Added: branches/upstream/libjavascript-packer-perl/current/t/01-io.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/01-io.t?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/01-io.t (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/01-io.t Wed Sep 16 17:23:02 2009
@@ -1,0 +1,80 @@
+#!perl -T
+
+# =========================================================================== #
+#
+# All these tests are stolen from JavaScript::Minifier
+#
+# =========================================================================== #
+
+use Test::More;
+
+my $not = 8;
+
+SKIP: {
+	eval( 'use JavaScript::Packer' );
+	
+	skip( 'JavaScript::Packer not installed!', $not ) if ( $@ );
+	
+	plan tests => $not;
+	
+	fileTest( 's1', 'clean', 'compression level "clean"' );
+	fileTest( 's2', 'shrink', 'compression level "shrink"' );
+	fileTest( 's3', 'obfuscate', 'compression level "obfuscate"' );
+	fileTest( 's4', 'best', 'compression level "best" whith short javascript' );
+	fileTest( 's5', 'best', 'compression level "best" whith long javascript' );
+	
+	my $var = 'var x = 2;';
+	JavaScript::Packer::minify( \$var );
+	is( $var, 'var x=2;', 'string literal input and ouput' );
+	$var = "var x = 2;\n;;;alert('hi');\nvar x = 2;";
+	JavaScript::Packer::minify( \$var );
+	is( $var, 'var x=2;var x=2;', 'scriptDebug option' );
+	$var = "var x = 2;";
+	JavaScript::Packer::minify( \$var, { 'copyright' => 'BSD' } );
+	is( $var, '/* BSD */var x=2;', 'copyright option');
+}
+
+sub filesMatch {
+	my $file1 = shift;
+	my $file2 = shift;
+	my $a;
+	my $b;
+	
+	while (1) {
+		$a = getc($file1);
+		$b = getc($file2);
+		
+		if (!defined($a) && !defined($b)) { # both files end at same place
+			return 1;
+		}
+		elsif (
+			!defined($b) || # file2 ends first
+			!defined($a) || # file1 ends first
+			$a ne $b
+		) {     # a and b not the same
+			return 0;
+		}
+	}
+}
+
+sub fileTest {
+	my $filename	= shift;
+	my $compress	= shift || 'minify';
+	my $comment	= shift || '';
+	
+	open(INFILE, 't/scripts/' . $filename . '.js') or die("couldn't open file");
+	open(GOTFILE, '>t/scripts/' . $filename . '-got.js') or die("couldn't open file");
+	
+	my $js = join( '', <INFILE> );
+	JavaScript::Packer::minify( \$js, { 'compress' => $compress } );
+	print GOTFILE $js;
+	close(INFILE);
+	close(GOTFILE);
+	
+	open(EXPECTEDFILE, 't/scripts/' . $filename . '-expected.js') or die("couldn't open file");
+	open(GOTFILE, 't/scripts/' . $filename . '-got.js') or die("couldn't open file");
+	ok( filesMatch(GOTFILE, EXPECTEDFILE), $comment );
+	close(EXPECTEDFILE);
+	close(GOTFILE);
+}
+

Added: branches/upstream/libjavascript-packer-perl/current/t/pod.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/pod.t?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/pod.t (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/pod.t Wed Sep 16 17:23:02 2009
@@ -1,0 +1,12 @@
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More;
+
+# Ensure a recent version of Test::Pod
+my $min_tp = 1.22;
+eval "use Test::Pod $min_tp";
+plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
+
+all_pod_files_ok();

Added: branches/upstream/libjavascript-packer-perl/current/t/scripts/s1-expected.js
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/scripts/s1-expected.js?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/scripts/s1-expected.js (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/scripts/s1-expected.js Wed Sep 16 17:23:02 2009
@@ -1,0 +1,2 @@
+function(hmpf){var argh='blah blubb';var y=3;alert(argh);var x=1;//@a  
+var x=hmpf;/*@abcd var x=1;@*/abcd var z=$H()};/*@abcd var x=1;@*/

Added: branches/upstream/libjavascript-packer-perl/current/t/scripts/s1.js
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/scripts/s1.js?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/scripts/s1.js (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/scripts/s1.js Wed Sep 16 17:23:02 2009
@@ -1,0 +1,16 @@
+function ( hmpf ) {
+	var argh = 'blah blubb';
+	var y = 3;
+	alert( argh );
+	var x = 1;//@a  
+	var x = hmpf;/*@ abcd
+var x = 1;@*/ abcd
+/*a*/  
+/*
+blah
+*/
+	var z = $H();  // comment
+};
+// another comment
+/*@ abcd
+var x = 1;@*/

Added: branches/upstream/libjavascript-packer-perl/current/t/scripts/s2-expected.js
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/scripts/s2-expected.js?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/scripts/s2-expected.js (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/scripts/s2-expected.js Wed Sep 16 17:23:02 2009
@@ -1,0 +1,2 @@
+function(a){var c='blah blubb';var y=3;alert(c);var x=1;//@a  
+var b=a;/*@abcd var x=1;@*/abcd var z=$H()};/*@abcd var x=1;@*/

Added: branches/upstream/libjavascript-packer-perl/current/t/scripts/s2.js
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/scripts/s2.js?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/scripts/s2.js (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/scripts/s2.js Wed Sep 16 17:23:02 2009
@@ -1,0 +1,16 @@
+function ( hmpf ) {
+	var argh = 'blah blubb';
+	var y = 3;
+	alert( argh );
+	var x = 1;//@a  
+	var b = hmpf;/*@ abcd
+var x = 1;@*/ abcd
+/*a*/  
+/*
+blah
+*/
+	var z = $H();  // comment
+};
+// another comment
+/*@ abcd
+var x = 1;@*/

Added: branches/upstream/libjavascript-packer-perl/current/t/scripts/s3-expected.js
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/scripts/s3-expected.js?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/scripts/s3-expected.js (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/scripts/s3-expected.js Wed Sep 16 17:23:02 2009
@@ -1,0 +1,1 @@
+eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('9(a){0 c=\'d 8\';0 6=3;7(c);0 4=1;//@a  \n0 b=a;/*@5 0 4=1;@*/5 0 e=$2()};',15,15,'var||H||x|abcd|y|alert|blubb|function||||blah|z'.split('|'),0,{}))

Added: branches/upstream/libjavascript-packer-perl/current/t/scripts/s3.js
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/scripts/s3.js?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/scripts/s3.js (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/scripts/s3.js Wed Sep 16 17:23:02 2009
@@ -1,0 +1,14 @@
+function ( hmpf ) {
+	var argh = 'blah blubb';
+	var y = 3;
+	alert( argh );
+	var x = 1;//@a  
+	var b = hmpf;/*@ abcd
+var x = 1;@*/ abcd
+/*a*/  
+/*
+blah
+*/
+	var z = $H();  // comment
+};
+// another comment

Added: branches/upstream/libjavascript-packer-perl/current/t/scripts/s4-expected.js
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/scripts/s4-expected.js?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/scripts/s4-expected.js (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/scripts/s4-expected.js Wed Sep 16 17:23:02 2009
@@ -1,0 +1,2 @@
+function(a){var c='blah blubb';var y=3;alert(c);var x=1;//@a  
+var b=a;/*@abcd var x=1;@*/abcd var z=$H()};/*@abcd var x=1;@*/

Added: branches/upstream/libjavascript-packer-perl/current/t/scripts/s4.js
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/scripts/s4.js?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/scripts/s4.js (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/scripts/s4.js Wed Sep 16 17:23:02 2009
@@ -1,0 +1,16 @@
+function ( hmpf ) {
+	var argh = 'blah blubb';
+	var y = 3;
+	alert( argh );
+	var x = 1;//@a  
+	var b = hmpf;/*@ abcd
+var x = 1;@*/ abcd
+/*a*/  
+/*
+blah
+*/
+	var z = $H();  // comment
+};
+// another comment
+/*@ abcd
+var x = 1;@*/

Added: branches/upstream/libjavascript-packer-perl/current/t/scripts/s5-expected.js
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/scripts/s5-expected.js?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/scripts/s5-expected.js (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/scripts/s5-expected.js Wed Sep 16 17:23:02 2009
@@ -1,0 +1,1 @@
+eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('5 K=7 2(){5 g=7 10();5 f=2(e){8(!e.4(\'H\'))n;7 D.w(\'/9\'+e.4(\'H\')+\'z.y?\'+6.h(6.l()*m)+\'=\'+6.h(6.l()*m),{x:\'4\',B:2(d){5 c=7 M(\'T\').p(d.v.1m());c.1l(\'1e\').u(2(b){5 a=7 1d();a.P=b.12(\'P\');g[g.L]=a})}});8(e.4(\'N\')){e.4(\'N\').u(2(a){f(a)})}}n{S:2(){5 b=E.W();b.u(2(a){f(a)})}}}5 9=7 2(){n{t:2(){5 e=$A(9.t.16);5 d=e.1f();8(!d){n}5 c=7 M(\'T\');c.15({\'1b\':\'O\',\'1q\':\'O\'});8($(\'i\').1a()){7 r.1c(\'i\',{13:2(){7 D.w(\'/9\'+d+\'z.y?\'+6.h(6.l()*m)+\'=\'+6.h(6.l()*m),{x:\'4\',B:2(a){5 b=c.p(a.v);$(\'i\').p(b);7 r.I(\'i\',{J:0.G})}})},17:0.G})}Q{7 D.w(\'/9\'+d+\'z.y?\'+6.h(6.l()*m)+\'=\'+6.h(6.l()*m),{x:\'4\',B:2(a){$(\'i\').p(c.p(a.v));7 r.I(\'i\',{J:0.14})}})}}}}5 j=0;V.3.19({F:2(o){n 1k.F(o)},Z:2(s){n s.18()}});2 q(b,a){b=b?b:\'/\';8(!j&&b){j=1;9.t(b);E.t(b);C()}}2 1j(b,a){8(!j){3.U(b,a)}q(b,a)}2 C(){5 a=$A(r.1h);8(a.L>0){11("C();",1p)}Q{j=0}}V.1o=2(){3.1g();3.1n(q);E.X();k=3.1i();k=k?k:\'/\';8(3.Y()){8(!j){3.U(k,R)}q(k,R)}K.S()}',62,89,'||function|dhtmlHistory|get|var|Math|new|if|content||||||||round|div_content|wait|initialLocation|random|99999|return||update|handle_location|Effect||process|each|responseText|Request|method|htm|index||onComplete|reset_wait|Ajax|menu|toJSON|01|loc|Appear|from|image|length|Element|subs|0px|src|else|null|preload|div|add|window|get_menu_hash|init|isFirstLoad|fromJSON|Array|setTimeout|readAttribute|afterFinish|00|setStyle|arguments|to|evalJSON|create|visible|padding|Fade|Image|img|shift|initialize|Queue|getCurrentLocation|handle_click|Object|select|stripScripts|addListener|onload|1000|margin'.split('|'),0,{}))

Added: branches/upstream/libjavascript-packer-perl/current/t/scripts/s5.js
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-packer-perl/current/t/scripts/s5.js?rev=44142&op=file
==============================================================================
--- branches/upstream/libjavascript-packer-perl/current/t/scripts/s5.js (added)
+++ branches/upstream/libjavascript-packer-perl/current/t/scripts/s5.js Wed Sep 16 17:23:02 2009
@@ -1,0 +1,185 @@
+var image = new function() {
+	var preloaded_images = new Array();
+	
+	var check_content = function( item ) {
+		if ( ! item.get( 'loc' ) ) return;
+
+		new Ajax.Request(
+			'/content' + item.get( 'loc' ) + 'index.htm?' + Math.round( Math.random() * 99999 ) + '=' + Math.round( Math.random() * 99999 ),
+			{
+				method:	'get',
+				onComplete	: function( req ) {
+					var div = new Element( 'div' ).update( req.responseText.stripScripts() );
+
+					div.select( 'img' ).each(
+						function( img ) {
+							var bild = new Image();
+							bild.src = img.readAttribute('src');
+							
+							preloaded_images[preloaded_images.length] = bild;
+							//alert( bild.src );
+						}
+					)
+				}
+			}
+		);
+
+		if ( item.get( 'subs' ) ) {
+			item.get( 'subs' ).each(
+				function( sub_item ) {
+					check_content( sub_item );
+				}
+			);
+		}
+	}
+
+	return {
+		preload	: function() {
+			var menu_hash = menu.get_menu_hash();
+
+			menu_hash.each(
+				function( item ) {
+					check_content( item );
+				}
+			);
+		}
+	}
+}
+
+var content = new function() {
+	return {
+		process	: function() {
+			var args = $A( content.process.arguments );
+
+			var loc = args.shift();
+
+			if ( ! loc ) { return; }
+
+			var inner_div = new Element( 'div' );
+
+			inner_div.setStyle(
+				{
+					'padding'	: '0px',
+					'margin'	: '0px'
+				}
+			);
+
+			if ( $( 'div_content' ).visible() ) {
+				new Effect.Fade(
+					'div_content',
+					{
+						afterFinish	: function() {
+
+							new Ajax.Request(
+								'/content' + loc + 'index.htm?' + Math.round( Math.random() * 99999 ) + '=' + Math.round( Math.random() * 99999 ),
+								{
+									method:	'get',
+									onComplete	: function( req ) {
+
+										var the_content = inner_div.update( req.responseText );
+
+										$( 'div_content' ).update( the_content );
+
+										new Effect.Appear(
+											'div_content',
+											{
+												from	: 0.01
+											}
+										);
+									}
+								}
+							)
+						},
+						to	: 0.01
+					}
+				);
+			}
+			else {
+				new Ajax.Request(
+					'/content' + loc + 'index.htm?' + Math.round( Math.random() * 99999 ) + '=' + Math.round( Math.random() * 99999 ),
+					{
+						method:	'get',
+						onComplete	: function( req ) {
+
+							$( 'div_content' ).update( inner_div.update( req.responseText ) );
+
+							new Effect.Appear(
+								'div_content',
+								{
+									from	: 0.00
+								}
+							);
+						}
+					}
+				)
+			}
+		}
+	}
+}
+
+// ----------------------------------------------------------------------------
+
+var wait = 0;
+
+window.dhtmlHistory.create(
+	{
+		toJSON: function(o) {
+			return Object.toJSON(o);
+		},
+		fromJSON: function(s) {
+			return s.evalJSON();
+		}
+	}
+);
+
+function handle_location( newLocation, historyData ) {
+	newLocation = newLocation ? newLocation : '/';
+
+	if ( ! wait && newLocation ) {
+		wait = 1;
+
+		content.process( newLocation );
+		menu.process( newLocation );
+
+		reset_wait();
+	}
+}
+
+function handle_click( newLocation, historyData ) {
+	if ( ! wait ) {
+		dhtmlHistory.add( newLocation, historyData );
+	}
+	handle_location( newLocation, historyData );
+}
+
+function reset_wait() {
+	var queue = $A(Effect.Queue);
+
+	if ( queue.length > 0 ) {
+		setTimeout( "reset_wait();", 1000 );
+	}
+	else {
+		wait = 0;
+	}
+}
+
+window.onload = function() {
+	dhtmlHistory.initialize();
+	dhtmlHistory.addListener(handle_location);
+
+	menu.init();
+
+	initialLocation = dhtmlHistory.getCurrentLocation();
+
+	initialLocation = initialLocation ? initialLocation : '/';
+
+	if ( dhtmlHistory.isFirstLoad() ) {
+		if ( ! wait ) {
+			dhtmlHistory.add( initialLocation, null );
+		}
+		handle_location( initialLocation, null );
+	}
+
+	image.preload();
+	//alert( 'onload' );
+}




More information about the Pkg-perl-cvs-commits mailing list