PhantomJS/Examples.pm untested

filter: Statementstmt 0.0% 0 / 5 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 1 Podpod n/a totaltotal 0.0% 0 / 6 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
CRAP 2.0
1 package WWW::Mechanize::PhantomJS::Examples;
2  
3 ###############################################################################
4 #
5 # Examples - WWW::Mechanize::PhantomJS examples.
6 #
7 # A documentation only module showing the examples that are
8 # included in the WWW::Mechanize::PhantomJS distribution. This
9 # file was generated automatically via the gen_examples_pod.pl
10 # program that is also included in the examples directory.
11 #
12 # Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
13 #
14 # Documentation after __END__
15 #
16  
17 use strict;
18 our $VERSION= '0.24';
19  
20 1;
21  
22 __END__
23  
24 =pod
25  
26 =head1 NAME
27  
28 Examples - WWW::Mechanize::PhantomJS example programs.
29  
30 =head1 DESCRIPTION
31  
32 This is a documentation only module showing the examples that are
33 included in the L<WWW::Mechanize::PhantomJS> distribution.
34  
35 This file was auto-generated via the C<gen_examples_pod.pl>
36 program that is also included in the examples directory.
37  
38 =head1 Example programs
39  
40 The following is a list of the 4 example programs that are included in the WWW::Mechanize::PhantomJS distribution.
41  
42 =over
43  
44 =item * L<Example: url-to-image.pl> Take a screenshot of a website
45  
46 =item * L<Example: html-to-pdf.pl> Convert HTML to PDF
47  
48 =item * L<Example: dump-links.pl> Dump links on a webpage
49  
50 =item * L<Example: javascript.pl> Execute Javascript in the webpage context
51  
52 =back
53  
54 =head2 Example: url-to-image.pl
55  
56 use strict;
57 use File::Spec;
58 use File::Basename 'dirname';
59 use WWW::Mechanize::PhantomJS;
60
61 my $mech = WWW::Mechanize::PhantomJS->new(
62 launch_arg => ['ghostdriver/src/main.js' ],
63 );
64
65 sub show_screen() {
66 my $page_png = $mech->content_as_png();
67
68 my $fn= File::Spec->rel2abs(dirname($0)) . "/screen.png";
69 open my $fh, '>', $fn
70 or die "Couldn't create '$fn': $!";
71 binmode $fh, ':raw';
72 print $fh $page_png;
73 close $fh;
74
75 #system(qq(start "Progress" "$fn"));
76 };
77
78 $mech->get('http://act.yapc.eu/gpw2014');
79
80 show_screen;
81  
82  
83 Download this example: L<http://cpansearch.perl.org/src/CORION/WWW-Mechanize-PhantomJS-0.24/examples/url-to-image.pl>
84  
85 =head2 Example: html-to-pdf.pl
86  
87 #!perl -w
88 use strict;
89 use WWW::Mechanize::PhantomJS;
90
91 my $mech = WWW::Mechanize::PhantomJS->new(
92 launch_arg => ['ghostdriver/src/main.js' ],
93 );
94
95 for my $url (@ARGV) {
96 print "Loading $url";
97 $mech->get($url);
98
99 my $fn= 'screen.pdf';
100 my $page_pdf = $mech->content_as_pdf(
101 filename => $fn,
102 );
103 print "\nSaved $url as $fn\n";
104 };
105  
106 Download this example: L<http://cpansearch.perl.org/src/CORION/WWW-Mechanize-PhantomJS-0.24/examples/html-to-pdf.pl>
107  
108 =head2 Example: dump-links.pl
109  
110 use strict;
111 use WWW::Mechanize::PhantomJS;
112
113 my $mech = WWW::Mechanize::PhantomJS->new(
114 launch_arg => ['ghostdriver/src/main.js' ],
115 );
116
117 $mech->get_local('links.html');
118
119 sleep 5;
120
121 print $_->get_attribute('href'), "\n\t-> ", $_->get_attribute('innerHTML'), "\n"
122 for $mech->selector('a.download');
123
124 =head1 NAME
125
126 dump-links.pl - Dump links on a webpage
127
128 =head1 SYNOPSIS
129
130 dump-links.pl
131
132 =head1 DESCRIPTION
133
134 This program demonstrates how to read elements out of the PhantomJS
135 DOM and how to get at text within nodes.
136
137 =cut
138  
139 Download this example: L<http://cpansearch.perl.org/src/CORION/WWW-Mechanize-PhantomJS-0.24/examples/dump-links.pl>
140  
141 =head2 Example: javascript.pl
142  
143 #!perl -w
144 use strict;
145 use WWW::Mechanize::PhantomJS;
146
147 my $mech = WWW::Mechanize::PhantomJS->new(
148 launch_arg => ['ghostdriver/src/main.js' ],
149 );
150
151
152 $mech->get_local('links.html');
153
154 print $mech->eval_in_page(<<'JS');
155 ["Just","another","Perl","Hacker"].join(" ");
156 JS
157
158 =head1 NAME
159
160 javascript.pl - execute Javascript in a page
161
162 =head1 SYNOPSIS
163
164 javascript.pl
165
166 =head1 DESCRIPTION
167
168 B<This program> demonstrates how to execute simple
169 Javascript in a page.
170
171 =cut
172  
173 Download this example: L<http://cpansearch.perl.org/src/CORION/WWW-Mechanize-PhantomJS-0.24/examples/javascript.pl>
174  
175 =head1 AUTHOR
176  
177 Max Maischein C<corion@cpan.org>
178  
179 Contributed examples contain the original author's name.
180  
181 =head1 COPYRIGHT
182  
183 Copyright 2009-2020 by Max Maischein C<corion@cpan.org>.
184  
185 All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
186  
187 =cut