WWW/Mechanize/Firefox/DSL.pm

filter: Statementstmt 77.4% 24 / 31 Branchbran 25.0% 1 / 4 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 67.3% 33 / 49 CC 5 SCAR 15.6
CC
5
Cov
68%
import
8.5
BEGIN
1.0
BEGIN
1.0
CRAP 4.8
« HTML/Display/MozRepl.pm ↑ Summary Firefox/Application/API40.pm »
1 package WWW::Mechanize::Firefox::DSL;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use WWW::Mechanize::Firefox;
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::Firefox
11 ]);
12  
13 =head1 NAME
14  
15 WWW::Mechanize::Firefox::DSL - Domain Specific Language for short scripts
16  
17 =head1 SYNOPSIS
18  
19 use WWW::Mechanize::Firefox::DSL '$mech';
20  
21 get 'http://google.de';
22
23 my @links = selector('a');
24 print $_->{innerHTML},"\n" for @links;
25
26 click($links[0]);
27
28 print content;
29  
30 This module exports all methods of one WWW::Mechanize::Firefox
31 object as subroutines. That way, you can write short scripts without
32 cluttering every line with C<< $mech-> >>.
33  
34 This module is highly experimental and might vanish from the distribution
35 again if I find that it is useless.
36  
37 =cut
38  
39 1 ▶sub import {
Subroutine import: called CC=5 SCAR=21.4
40 1 my ($class, %options);
41 1 ▶ if (@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 0 1 1
42 0 ($class, $options{ name }) = @_;
43 } else {
44 1 ($class, %options) = @_;
45 };
46 1 ▶ my $target = delete $options{ target } || caller;
Condition33%1/3
delete $options{'target'} || caller
l!l&&r!l&&!r
010
MC/DC0%0/2
delete $options{'target'} || caller
delete $options{'target'} caller
Truth table33%1/3
A || B
A= delete $options{'target'}B= caller
ABresult
1X1
011
000
47 1 ▶ my $name = delete $options{ name } || '$mech';
Condition50%1/2
delete $options{'name'} || '$mech'
l!l
01
MC/DC0%0/1
delete $options{'name'} || '$mech'
delete $options{'name'}
Truth table50%1/2
A
A= delete $options{'name'}
Aresult
11
00
48 1 my $mech = WWW::Mechanize::Firefox->new(%options);
49
50 0 ▶ $name =~ s/^[\$]//
Branch: 1 branch
BranchTrueFalseTotal
$name =~ s/^[\$]// or croak("Variable name must start with \$") 0 0 0
51 or croak 'Variable name must start with $';
52 {
53 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.2
54 0 *{"$target\::$name"} = \$mech;
55 0 import Object::Import \${"$target\::$name"},
56 deref => 1,
57 target => $target,
58 ;
59 };
60 };
61  
62 1 1;
63  
64 =head1 AUTHORS
65  
66 Max Maischein C<corion@cpan.org>
67  
68 =head1 COPYRIGHT (c)
69  
70 Copyright 2009-2014 by Max Maischein C<corion@cpan.org>.
71  
72 =head1 LICENSE
73  
74 This module is released under the same terms as Perl itself.
75  
76 =cut
« HTML/Display/MozRepl.pm ↑ Summary Firefox/Application/API40.pm »