Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

JS Packager

  • Loading branch information...
commit ff2406e9b46db4c111ffaddfeb9179a0a1b78767 1 parent a5d44d5
@tmueller authored
View
75 script/lib/Packager.pm
@@ -0,0 +1,75 @@
+package Packager;
+use Mouse;
+
+use uni::perl;
+
+use Data::Dumper ();
+use Time::HiRes ();
+use JavaScript::Minifier ();
+use Packager::Types ();
+
+with 'MouseX::Getopt';
+
+# Autoflush
+BEGIN { $| = 1 }
+
+################################################################################
+# command line args
+has files => (
+ traits => ['Array'],
+ is => 'rw',
+ isa => 'ArrayRef[Path::Class::File]',
+ required => 1,
+ documentation => 'files to compress',
+ coerce => 1,
+ handles => {
+ all_files => 'elements',
+ },
+);
+
+has outfile => (
+ is => 'rw',
+ isa => 'Path::Class::File',
+ coerce => 1,
+ required => 1,
+);
+
+has _outdir => (
+ is => 'rw',
+ isa => 'Path::Class::Dir',
+ lazy => 1,
+ default => sub { shift->outfile->dir },
+);
+
+has minify => (
+ is => 'rw',
+ isa => 'Bool',
+ default => 0,
+);
+
+
+sub run {
+ my $self = shift;
+ my $jscode = '';
+
+ for ($self->all_files) {
+ $jscode .= '//'. $_->basename . "\n";
+ $jscode .= $_->slurp;
+ $jscode .= "\n\n";
+ }
+
+ if ($self->minify) {
+ my ($mini, $fh);
+ open $fh, '>', \$mini;
+ JavaScript::Minifier::minify(input => $jscode, outfile => $fh);
+ $jscode = $mini;
+ }
+
+ $self->_outdir->mkpath;
+ $self->outfile->touch;
+ print { $self->outfile->openw } $jscode;
+}
+
+
+no Mouse;
+1;
View
55 script/lib/Packager/Types.pm
@@ -0,0 +1,55 @@
+package Packager::Types;
+
+use Mouse::Util::TypeConstraints;
+use Path::Class::Dir;
+use Path::Class::File;
+use Scalar::Util;
+use Data::Dumper;
+
+class_type('Path::Class::Dir');
+class_type('Path::Class::File');
+
+subtype 'ArrayRef[Path::Class::File]'
+ => as 'ArrayRef'
+ => where {
+ for my $file (@$_) {
+ return 0 unless (Scalar::Util::blessed($file));
+ return 0 unless ($file->can('is_dir'));
+ return 0 if ($file->is_dir);
+ }
+ return 1;
+ };
+
+subtype 'ArrayRef[Path::Class::Dir]'
+ => as 'ArrayRef'
+ => where {
+ for my $file (@$_) {
+ return 0 unless (Scalar::Util::blessed($file));
+ return 0 unless ($file->can('is_dir'));
+ return 0 unless ($file->is_dir);
+ }
+ return 1;
+ };
+
+coerce 'Path::Class::File' => from 'Str' => via { Path::Class::File->new($_) };
+coerce 'Path::Class::Dir' => from 'Str' => via { Path::Class::Dir->new($_) };
+coerce 'ArrayRef[Path::Class::File]' => from 'ArrayRef[Str]' => via {
+ my $stringarray = $_;
+ [ map { Path::Class::File->new($_) } @$stringarray ];
+};
+coerce 'ArrayRef[Path::Class::Dir]' => from 'ArrayRef[Str]' => via {
+ my $stringarray = $_;
+ [ map { Path::Class::Dir->new($_) } @$stringarray ];
+};
+
+
+
+# optionally add Getopt option type
+eval { require MouseX::Getopt; };
+if ( !$@ ) {
+ MouseX::Getopt::OptionTypeMap->add_option_type_to_map( $_, '=s', )
+ for ('Path::Class::Dir', 'Path::Class::File');
+}
+
+no Mouse::Util::TypeConstraints;
+1;
View
25 script/package.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+# Autoflush
+BEGIN { $| = 1 }
+
+use strict;
+use utf8;
+
+use Data::Dumper;
+use FindBin;
+use lib $FindBin::Bin.'/lib';
+
+use Packager;
+
+my @files = qw(Required.js Attribute.js Attribute/Lazy.js Attributes.js);
+
+my $outfile = $FindBin::Bin.'/../../lib/MooTools/Class/Attributes.js';
+my $indir = $FindBin::Bin.'/../lib/MooTools/Class/';
+
+Packager->new_with_options(
+ files => [ map { $indir.$_ } @files ],
+ outfile => $outfile
+)->run;
+
+1;
View
36 script/role_composition.pl
@@ -0,0 +1,36 @@
+use strict;
+use uni::perl;
+
+{
+ package TestRole;
+ use uni::perl;
+ use Moose::Role;
+
+ before say => sub { say 'from role' }
+
+}
+
+{
+ package TestClass::Before;
+ use uni::perl;
+ use Moose;
+
+ with 'TestRole';
+
+ sub say { say 'from Class (before)' }
+
+}
+
+{
+ package TestClass::After;
+ use uni::perl;
+ use Moose;
+
+ sub say { say 'from Class (after)' }
+
+ with 'TestRole';
+
+}
+
+TestClass::Before->new->say;
+TestClass::After->new->say;
View
27 script/rw_inheritance.pl
@@ -0,0 +1,27 @@
+use strict;
+use 5.010;
+
+{
+ package T1;
+ use Moose;
+
+ has t => (
+ is => "rw"
+ );
+}
+
+{
+ package T2;
+ use Moose;
+ extends 'T1';
+
+ has t => (
+ is => "ro"
+ );
+}
+
+
+my $test = T2->new(t => 1);
+
+say $test->t;
+say $test->can('t');
Please sign in to comment.
Something went wrong with that request. Please try again.