| 1 | package WWW::Mechanize::Chrome::DSL; | ||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use WWW::Mechanize::Chrome; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use Object::Import; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.80'; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | our @CARP_NOT = (qw[ | |||||||||||||||||||
| 10 | WWW::Mechanize::Chrome | ||||||||||||||||||||
| 11 | ]); | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | WWW::Mechanize::Chrome::DSL - Domain Specific Language for short scripts | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | use Log::Log4perl qw(:easy); | ||||||||||||||||||||
| 20 | Log::Log4perl->easy_init($ERROR); | ||||||||||||||||||||
| 21 | use WWW::Mechanize::Chrome::DSL '$mech'; | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | get 'http://google.de'; | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | my @links = selector('a'); | ||||||||||||||||||||
| 26 | print $_->{innerHTML},"\n" for @links; | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | click($links[0]); | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | print content; | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | This module exports all methods of one WWW::Mechanize::Chrome | ||||||||||||||||||||
| 33 | object as subroutines. That way, you can write short scripts without | ||||||||||||||||||||
| 34 | cluttering every line with C<< $mech-> >>. | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | This module is highly experimental and might vanish from the distribution | ||||||||||||||||||||
| 37 | again if I find that it is useless. | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | sub import { | ||||||||||||||||||
|
Subroutine
import: not called CC=5 SCAR=30.9
| |||||||||||||||||||||
| 42 | 0 | my ($class, %options); | |||||||||||||||||||
| 43 | 0 | ▶ | if (@_ == 2) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | ($class, $options{ name }) = @_; | |||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||
| 46 | 0 | ($class, %options) = @_; | |||||||||||||||||||
| 47 | }; | ||||||||||||||||||||
| 48 | 0 | ▶ | my $target = delete $options{ target } || caller; | ||||||||||||||||||
|
Condition0%0/3
delete $options{'target'} || caller
MC/DC0%0/2
delete $options{'target'} || caller
delete $options{'target'}
caller
Truth table0%0/3
A || B
A= delete $options{'target'}B= caller
| |||||||||||||||||||||
| 49 | 0 | ▶ | my $name = delete $options{ name } || '$mech'; | ||||||||||||||||||
|
Condition0%0/2
delete $options{'name'} || '$mech'
MC/DC0%0/1
delete $options{'name'} || '$mech'
delete $options{'name'}
Truth table0%0/2
A
A= delete $options{'name'}
| |||||||||||||||||||||
| 50 | 0 | my $mech = WWW::Mechanize::Chrome->new(%options); | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | $name =~ s/^[\$]// | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | or croak 'Variable name must start with $'; | ||||||||||||||||||||
| 54 | { | ||||||||||||||||||||
| 55 | 0 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||
| 56 | 0 | *{"$target\::$name"} = \$mech; | |||||||||||||||||||
| 57 | 0 | import Object::Import \${"$target\::$name"}, | |||||||||||||||||||
| 58 | deref => 1, | ||||||||||||||||||||
| 59 | target => $target, | ||||||||||||||||||||
| 60 | ; | ||||||||||||||||||||
| 61 | }; | ||||||||||||||||||||
| 62 | }; | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 1 | 1; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =head1 AUTHORS | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | Max Maischein C<corion@cpan.org> | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =head1 COPYRIGHT (c) | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | Copyright 2009-2026 by Max Maischein C<corion@cpan.org>. | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =head1 LICENSE | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | This module is released under the same terms as Perl itself. | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | =cut | ||||||||||||||||||||