Permalink
Browse files

Only import what is actually required.

This helps to make startup ever-so-slightly faster (still way too slow
on an Atom though; about 770ms).
  • Loading branch information...
1 parent bba2e1b commit d2cb0206517b6505f3d24f46bd990ad91319bb2c @monsieurvideo monsieurvideo committed Apr 11, 2010
Showing with 22 additions and 12 deletions.
  1. +5 −6 FlashVideo/Generic.pm
  2. +2 −2 FlashVideo/Mechanize.pm
  3. +3 −3 FlashVideo/RTMPDownloader.pm
  4. +1 −1 get_flash_videos
  5. +11 −0 utils/combine-perl.pl
View
@@ -3,11 +3,8 @@ package FlashVideo::Generic;
use strict;
use FlashVideo::Utils;
-use File::Basename;
-use Memoize;
-use LWP::Simple;
use URI;
-use URI::Escape;
+use URI::Escape qw(uri_unescape);
my $video_re = qr!http[-:/a-z0-9%_.?=&]+@{[EXTENSIONS]}
# Grab any params that might be used for auth..
@@ -31,7 +28,9 @@ sub find_video {
(m{http://.+?(http://.+?@{[EXTENSIONS]})}i) ? $1 : $_
} ($browser->content =~ m{($video_re)}gi);
if (@flv_urls) {
- memoize("LWP::Simple::head");
+ require LWP::Simple;
+ require Memoize;
+ Memoize::memoize("LWP::Simple::head");
@flv_urls = sort { (head($a))[1] <=> (head($b))[1] } @flv_urls;
$possible_filename = (split /\//, $flv_urls[-1])[-1];
@@ -156,7 +155,7 @@ sub search_for_flv_in_swf {
if ($swf_data =~ m{(http://.{10,300}?\.flv)}i) {
my $flv_url = $1;
- my $filename = uri_unescape(basename(URI->new($flv_url)->path()));
+ my $filename = uri_unescape(File::Basename::basename(URI->new($flv_url)->path()));
$filename =~ s/\.flv$//i;
return ($flv_url, $filename);
View
@@ -2,7 +2,7 @@
package FlashVideo::Mechanize;
use WWW::Mechanize;
use FlashVideo::Downloader;
-use Encode;
+use Encode ();
use strict;
use base "WWW::Mechanize";
@@ -79,7 +79,7 @@ sub update_html {
}
if($charset) {
- eval { $html = decode($charset, $html) };
+ eval { $html = Encode::decode($charset, $html) };
FlashVideo::Utils::error("Failed decoding as $charset: $@") if $@;
}
}
@@ -3,7 +3,6 @@ package FlashVideo::RTMPDownloader;
use strict;
use base 'FlashVideo::Downloader';
-use Fcntl;
use IPC::Open3;
use Symbol qw(gensym);
use FlashVideo::Utils;
@@ -30,6 +29,7 @@ sub download {
my($r_fh, $w_fh); # So Perl doesn't close them behind our back..
if ($rtmp_data->{live} && $::opt{play}) {
+ require Fcntl;
# Playing live stream, we pipe this straight to the player, rather than
# saving on disk.
# XXX: The use of /dev/fd could go away now rtmpdump supports streaming to
@@ -40,12 +40,12 @@ sub download {
my $pid = fork;
die "Fork failed" unless defined $pid;
if(!$pid) {
- fcntl $r_fh, F_SETFD, ~FD_CLOEXEC;
+ fcntl $r_fh, Fcntl::F_SETFD, ~Fcntl::FD_CLOEXEC;
exec $self->replace_filename($::opt{player}, "/dev/fd/" . fileno $r_fh);
die "Exec failed\n";
}
- fcntl $w_fh, F_SETFD, ~FD_CLOEXEC;
+ fcntl $w_fh, Fcntl::F_SETFD, ~Fcntl::FD_CLOEXEC;
$rtmp_data->{flv} = "/dev/fd/" . fileno $w_fh;
$self->{stream} = undef;
View
@@ -21,8 +21,8 @@
use strict;
use Encode ();
+use File::Basename qw(basename);
use File::stat;
-use File::Basename;
use Getopt::Long;
use Text::Wrap;
View
@@ -89,6 +89,7 @@ sub process_file {
}
if(@items) {
$output .= "BEGIN { no strict 'refs'; ";
+ @items = filter_imports($file, @items);
for my $item(@items) {
next if $item =~ /^\d/;
next if $item =~ /^RC_/;
@@ -157,3 +158,13 @@ sub module_to_path {
$file .= ".pm";
return $file;
}
+
+sub filter_imports {
+ my($file, @imports) = @_;
+
+ open my $fh, "<", $file or die $!;
+ my $text = join "", <$fh>;
+
+ return grep { $text =~ /\Q$_\E/ } @imports;
+}
+

0 comments on commit d2cb020

Please sign in to comment.