From 8e10b0b3919e345dd059fa344ba0f963fdb52728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Sun, 30 Oct 2011 19:55:38 +0100 Subject: [PATCH 1/7] Optimize Chrome::Term initial loading Load the following modules only when used: - Term::ReadKey - Term::ReadLine (and its dependencies such as Term::ReadLine::Gnu) - Term::UI - Encode This optimizes runtime for most use cases (DZ commands that do not require user interaction). --- lib/Dist/Zilla/Chrome/Term.pm | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/Dist/Zilla/Chrome/Term.pm b/lib/Dist/Zilla/Chrome/Term.pm index 2a8272a77..81b1a2a1e 100644 --- a/lib/Dist/Zilla/Chrome/Term.pm +++ b/lib/Dist/Zilla/Chrome/Term.pm @@ -10,11 +10,7 @@ terminal environment. It's the default chrome used by L. =cut use Dist::Zilla::Types qw(OneZero); -use Encode qw(decode_utf8); use Log::Dispatchouli 1.102220; -use Term::ReadLine; -use Term::ReadKey; -use Term::UI; use namespace::autoclean; @@ -38,9 +34,22 @@ has term_ui => ( is => 'ro', isa => 'Object', lazy => 1, - default => sub { Term::ReadLine->new('dzil') }, + default => sub { + require Term::ReadLine; + require Term::UI; + Term::ReadLine->new('dzil') + }, ); +sub decode_utf8 ($;$) +{ + require Encode; + no warnings 'redefine'; + *decode_utf8 = \&Encode::decode_utf8; + goto \&decode_utf8; +} + + sub prompt_str { my ($self, $prompt, $arg) = @_; $arg ||= {}; @@ -81,9 +90,11 @@ sub prompt_any_key { if ($isa_tty) { local $| = 1; print $prompt; - Term::ReadKey::ReadMode 'cbreak'; + + require Term::ReadKey; + Term::ReadKey::ReadMode('cbreak'); Term::ReadKey::ReadKey(0); - Term::ReadKey::ReadMode 'normal'; + Term::ReadKey::ReadMode('normal'); print "\n"; } } From 33f59d74c3c1b5e70fdcaaa20b8f5fc605a8d4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Sun, 30 Oct 2011 20:42:35 +0100 Subject: [PATCH 2/7] Optimize Dist::Zilla::Util startup Load Pod::Eventual at runtime only if abstract_from_file is used. This improves 'dzil authordeps' speed. --- lib/Dist/Zilla/Util.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Dist/Zilla/Util.pm b/lib/Dist/Zilla/Util.pm index 8a4256141..1f32e95b7 100644 --- a/lib/Dist/Zilla/Util.pm +++ b/lib/Dist/Zilla/Util.pm @@ -10,9 +10,16 @@ use String::RewritePrefix 0.002; # better string context behavior { package Dist::Zilla::Util::PEA; - use Pod::Eventual 0.091480; # better nonpod/blank events - use base 'Pod::Eventual'; - sub _new { bless {} => shift; } + @Dist::Zilla::Util::PEA::ISA = ('Pod::Eventual'); + sub _new { + # Load Pod::Eventual only when used (and not yet loaded) + unless (exists $INC{'Pod/Eventual.pm'}) { + require Pod::Eventual; + Pod::Eventual->VERSION(0.091480); # better nonpod/blank events + } + + bless {} => shift; + } sub handle_nonpod { my ($self, $event) = @_; return if $self->{abstract}; From 0cdade9f90cc38aede7ef2e5d0994a7115db14e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 31 Oct 2011 22:38:19 +0100 Subject: [PATCH 3/7] DZ::App: don't load Path::Class (not used here) --- lib/Dist/Zilla/App.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Dist/Zilla/App.pm b/lib/Dist/Zilla/App.pm index 7911fd24a..91531989f 100644 --- a/lib/Dist/Zilla/App.pm +++ b/lib/Dist/Zilla/App.pm @@ -8,7 +8,6 @@ use Carp (); use Dist::Zilla::MVP::Reader::Finder; use Dist::Zilla::Util; use Moose::Autobox; -use Path::Class; use Try::Tiny; sub global_opt_spec { From 3e126932141202fe2be4ef5ff398f78026bd4f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 31 Oct 2011 22:39:10 +0100 Subject: [PATCH 4/7] DZ:Util: load Path::Class and File::HomeDir on demand In Dist::Zilla::Util, load Path::Class and File::HomeDir only when _global_config_root is called. --- lib/Dist/Zilla/Util.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Dist/Zilla/Util.pm b/lib/Dist/Zilla/Util.pm index 1f32e95b7..d605afd2a 100644 --- a/lib/Dist/Zilla/Util.pm +++ b/lib/Dist/Zilla/Util.pm @@ -3,8 +3,6 @@ use warnings; package Dist::Zilla::Util; # ABSTRACT: random snippets of code that Dist::Zilla wants -use File::HomeDir (); -use Path::Class; use String::RewritePrefix 0.002; # better string context behavior { @@ -93,12 +91,14 @@ sub expand_config_package_name { } sub _global_config_root { - return dir($ENV{DZIL_GLOBAL_CONFIG_ROOT}) if $ENV{DZIL_GLOBAL_CONFIG_ROOT}; + require Path::Class; + return Path::Class::dir($ENV{DZIL_GLOBAL_CONFIG_ROOT}) if $ENV{DZIL_GLOBAL_CONFIG_ROOT}; + require File::HomeDir; my $homedir = File::HomeDir->my_home or Carp::croak("couldn't determine home directory"); - return dir($homedir)->subdir('.dzil'); + return Path::Class::dir($homedir)->subdir('.dzil'); } 1; From 47053175b30243fa8a5fe77bf85993d54b6b7d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 31 Oct 2011 23:21:11 +0100 Subject: [PATCH 5/7] DZ:A:C:new: don't load Path::Class (not used here) --- lib/Dist/Zilla/App/Command/new.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Dist/Zilla/App/Command/new.pm b/lib/Dist/Zilla/App/Command/new.pm index f1979dbf5..2b5ee8255 100644 --- a/lib/Dist/Zilla/App/Command/new.pm +++ b/lib/Dist/Zilla/App/Command/new.pm @@ -34,7 +34,6 @@ directory of 'default' profile. use MooseX::Types::Perl qw(DistName ModuleName); use Moose::Autobox; -use Path::Class; sub abstract { 'mint a new dist' } From 294607af4843302a80f4eef2eb38c6171da34812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 31 Oct 2011 23:23:50 +0100 Subject: [PATCH 6/7] DZ:A:C:setup: don't load Path::Class (not used here) --- lib/Dist/Zilla/App/Command/setup.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Dist/Zilla/App/Command/setup.pm b/lib/Dist/Zilla/App/Command/setup.pm index 0dcd4b6a1..729e24462 100644 --- a/lib/Dist/Zilla/App/Command/setup.pm +++ b/lib/Dist/Zilla/App/Command/setup.pm @@ -17,7 +17,6 @@ the most commonly needed F sections. =cut use autodie; -use Path::Class; sub abstract { 'set up a basic global config file' } From 4c85cf914071fc16973fc95236a9c7c1ce05e1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 31 Oct 2011 23:25:20 +0100 Subject: [PATCH 7/7] DZ:A:C:authordeps: load Path::Class only when used --- lib/Dist/Zilla/App/Command/authordeps.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Dist/Zilla/App/Command/authordeps.pm b/lib/Dist/Zilla/App/Command/authordeps.pm index 8402f581d..82129f90d 100644 --- a/lib/Dist/Zilla/App/Command/authordeps.pm +++ b/lib/Dist/Zilla/App/Command/authordeps.pm @@ -6,7 +6,6 @@ use Dist::Zilla::App -command; use Dist::Zilla::Util (); use Moose; -use Path::Class qw(dir); use List::MoreUtils qw(uniq); use Config::INI::Reader; @@ -37,10 +36,12 @@ sub opt_spec { sub execute { my ($self, $opt, $arg) = @_; + require Path::Class; + $self->log( $self->format_author_deps( $self->extract_author_deps( - dir(defined $opt->root ? $opt->root : '.'), + Path::Class::dir(defined $opt->root ? $opt->root : '.'), $opt->missing, ), ),