@@ -2,7 +2,7 @@ package CSS::Inliner;
2
2
use strict;
3
3
use warnings;
4
4
5
- our $VERSION = ' 3957 ' ;
5
+ our $VERSION = ' 3958 ' ;
6
6
7
7
use Carp;
8
8
@@ -41,7 +41,7 @@ support top level <style> declarations.
41
41
=cut
42
42
43
43
BEGIN {
44
- my $members = [' stylesheet' ,' css' ,' html' ,' html_tree' ,' entities' ,' query' ,' strip_attrs' ,' relaxed' ,' leave_style' ,' warns_as_errors' ,' content_warnings' ];
44
+ my $members = [' stylesheet' ,' css' ,' html' ,' html_tree' ,' entities' ,' query' ,' strip_attrs' ,' relaxed' ,' leave_style' ,' warns_as_errors' ,' content_warnings' , ' agent ' ];
45
45
46
46
# generate all the getter/setter we need
47
47
foreach my $member (@{$members }) {
@@ -59,8 +59,6 @@ BEGIN {
59
59
}
60
60
}
61
61
62
- =pod
63
-
64
62
=head1 METHODS
65
63
66
64
=over
@@ -84,6 +82,8 @@ relaxed - (optional) Relaxed HTML parsing which will attempt to interpret non-HT
84
82
85
83
NOTE: This argument is not compatible with passing an html_tree.
86
84
85
+ agent - (optional) Pass in a string containing a preferred user-agent, overrides the internal default provided by the module for handling remote documents
86
+
87
87
=cut
88
88
89
89
sub new {
@@ -118,7 +118,8 @@ sub new {
118
118
strip_attrs => (defined ($$params {strip_attrs }) && $$params {strip_attrs }) ? 1 : 0,
119
119
relaxed => (defined ($$params {relaxed }) && $$params {relaxed }) ? 1 : 0,
120
120
leave_style => (defined ($$params {leave_style }) && $$params {leave_style }) ? 1 : 0,
121
- warns_as_errors => (defined ($$params {warns_as_errors }) && $$params {warns_as_errors }) ? 1 : 0
121
+ warns_as_errors => (defined ($$params {warns_as_errors }) && $$params {warns_as_errors }) ? 1 : 0,
122
+ agent => (defined ($$params {agent }) && $$params {agent }) ? $$params {agent } : ' Mozilla/4.0'
122
123
};
123
124
124
125
bless $self , $class ;
@@ -133,8 +134,6 @@ sub new {
133
134
return $self ;
134
135
}
135
136
136
- =pod
137
-
138
137
=item fetch_file
139
138
140
139
Fetches a remote HTML file that supposedly contains both HTML and a
@@ -150,6 +149,10 @@ url argument for the requested document. For example:
150
149
151
150
$self->fetch_file({ url => 'http://www.example.com' });
152
151
152
+ Note that you can specify a user-agent to override the default user-agent
153
+ of 'Mozilla/4.0' within the constructor. Doing so may avoid certain issues
154
+ with agent filtering related to quirky webserver configs.
155
+
153
156
=cut
154
157
155
158
sub fetch_file {
@@ -161,7 +164,6 @@ sub fetch_file {
161
164
croak ' You must pass in hash params that contain a url argument' ;
162
165
}
163
166
164
- # fetch a absolutized version of the html
165
167
my $html = $self -> _fetch_html({ url => $$params {url } });
166
168
167
169
$self -> read ({ html => $html });
@@ -212,8 +214,6 @@ sub read_file {
212
214
return ();
213
215
}
214
216
215
- =pod
216
-
217
217
=item read
218
218
219
219
Reads passed html data and parses it. The intermediate data is stored in
@@ -256,8 +256,6 @@ sub read {
256
256
return ();
257
257
}
258
258
259
- =pod
260
-
261
259
=item inlinify
262
260
263
261
Processes the html data that was entered through either 'read' or
@@ -392,8 +390,6 @@ sub inlinify {
392
390
return $html . " \n " ;
393
391
}
394
392
395
- =pod
396
-
397
393
=item query
398
394
399
395
Given a particular selector return back the applicable styles
@@ -412,8 +408,6 @@ sub query {
412
408
return $self -> _query-> query($$params {selector });
413
409
}
414
410
415
- =pod
416
-
417
411
=item specificity
418
412
419
413
Given a particular selector return back the associated selectivity
@@ -432,8 +426,6 @@ sub specificity {
432
426
return $self -> _query-> get_specificity($$params {selector });
433
427
}
434
428
435
- =pod
436
-
437
429
=item content_warnings
438
430
439
431
Return back any warnings thrown while inlining a given block of content.
@@ -496,13 +488,14 @@ sub _fetch_url {
496
488
497
489
# Create a user agent object
498
490
my $ua = LWP::UserAgent-> new;
499
- $ua -> agent(' Mozilla/4.0' ); # masquerade as Mozilla/4.0
491
+
492
+ $ua -> agent($self -> _agent()); # masquerade as Mozilla/4.0 unless otherwise specified in the constructor
500
493
$ua -> protocols_allowed( [' http' ,' https' ] );
501
494
502
495
# Create a request
503
496
my $uri = URI-> new($$params {url });
504
497
505
- my $req = HTTP::Request-> new(' GET' ,$uri );
498
+ my $req = HTTP::Request-> new(' GET' , $uri , [ ' Accept ' => ' text/html, */* ' ] );
506
499
507
500
# Pass request to the user agent and get a response back
508
501
my $res = $ua -> request($req );
@@ -887,8 +880,6 @@ sub _grep_important_declarations {
887
880
888
881
1;
889
882
890
- =pod
891
-
892
883
=head1 Sponsor
893
884
894
885
This code has been developed under sponsorship of MailerMailer LLC,
0 commit comments