Commits

Toby Inkster committed 36e2053

Speed up start time by deferring loading certain modules.

  • Participants
  • Parent commits 2b81a0a

Comments (0)

Files changed (2)

File lib/Web/Magic.pm

 	$Web::Magic::VERSION   = '0.005';
 }
 
-use Acme::24 0.03                  qw//; 
 use Carp 0                         qw/croak carp confess/;
-use HTML::HTML5::Parser 0.100      qw//;
-use HTML::HTML5::Writer 0.100      qw//;
-use JSON::JOM 0.005                qw/from_json to_jom to_json/;
+use JSON::JOM 0.005                qw/to_jom from_json to_json/;
 use JSON::JOM::Plugins::Dumper 0   qw//;
 use JSON::JOM::Plugins::JsonPath 0 qw//;
 use LWP::UserAgent 0               qw//;
 use Object::Stash 0.002            qw/_stash/;
 use PerlX::QuoteOperator 0.04      qw//;
-use RDF::RDFa::Parser 1.096        qw//;
-use RDF::Trine 0.135               qw//;
 use Scalar::Util 0                 qw/blessed/;
 use Sub::Name 0                    qw/subname/;
 use Object::AUTHORITY 0            qw//;
 use URI 0                          qw//;
 use URI::Escape 0                  qw//;
-use XML::LibXML 1.70               qw//;
-use XML::LibXML::QuerySelector 0   qw//;
 use YAML::Any 0                    qw/Load Dump/;
 
 use overload
 	}
 	elsif ($func =~ /^[A-Z]/ and $func =~ /[a-z]/)
 	{
-		return sub { (shift)->set_request_header($func, @_); };
+		return sub { warn "FUNC: $func"; (shift)->set_request_header($func, @_); };
 	}
 	return;
 }
 	goto &$ref;
 }
 
+sub _deferred_load
+{
+	my $self = shift;
+	while (@_)
+	{
+		my $package = shift;
+		my $version = shift;
+		my $list    = (ref $_[0]) ? shift : [];
+		
+		next if UNIVERSAL::can($package, 'can');
+		#warn "DEFERRED LOAD: $package $version";
+		eval "use $package $version qw//;1" or croak $@;
+		$package->import(@$list);
+	}
+	$self;
+}
+
 sub set_request_method
 {
 	my ($self, @args) = @_;
 		}
 		elsif (blessed $body and $body->isa('RDF::Trine::Model'))
 		{
+			$self->_deferred_load('RDF::Trine' => '0.135');
+				
 			my $ser;
 			given ( $req->content_type//'xml' )
 			{
 		}
 		elsif (blessed $body and $body->isa('XML::LibXML::Document'))
 		{
+			$self->_deferred_load('XML::LibXML' => '1.70');
+			
 			my $ser;
 			given ( $req->content_type//'xml' )
 			{
 {
 	my ($self) = @_;
 	my $stash = $self->_stash;
-	
+
 	unless (exists $stash->{hashref})
 	{
 		$self->do_request(Accept => 'application/json, application/yaml, text/yaml');
 {
 	my ($self) = @_;
 	my $stash = $self->_stash;
-	
+
+	$self->_deferred_load(
+		'HTML::HTML5::Parser'        => '0.100',
+		'HTML::HTML5::Writer'        => '0.100',
+		'XML::LibXML'                => '1.70',
+		'XML::LibXML::QuerySelector' => 0,
+		);
+
 	unless (exists $stash->{dom})
 	{
 		$self->do_request(Accept => 'application/xml, text/xml, application/atom+xml, application/xhtml+xml, text/html');
 {
 	my ($self) = @_;
 	my $stash = $self->_stash;
-	
+
+	$self->_deferred_load(
+		'RDF::RDFa::Parser'    => '1.096',
+		'RDF::Trine'           => '0.135',
+		);
+
 	unless (exists $stash->{model})
 	{
 		$self->do_request(Accept => 'application/rdf+xml, text/turtle, application/xhtml+xml;q=0.1');
 	my ($self) = @_;
 	my $stash = $self->_stash;
 	
+	$self->_deferred_load('XML::Feed' => 0);
+	
 	unless (exists $stash->{feed})
 	{
 		my $response = $self->response(Accept => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.1');
 
 sub acme_24
 {
+	my ($self) = @_;
+	$self->_deferred_load('Acme::24'   => '0.03');
 	return 'Acme::24';
 }
 

File meta/makefile.ttl

 		"Sub::Name 0",
 		"URI 0",
 		"URI::Escape 0",
+		"XML::Feed 0",
 		"XML::LibXML 1.70",
 		"XML::LibXML::QuerySelector 0",
 		"YAML::Any 0".