Scripter/WindowGroup.pm

filter: Statementstmt 27.0% 10 / 37 Branchbran 12.5% 1 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 3 / 9 Podpod 100% 7 / 7 totaltotal 34.4% 21 / 61 SCAR 33.4
CC
7
Cov
24%
detach
12.0
bring_to_front
12.0
new_window
6.0
CRAP 28.1
« Scripter.pm ↑ Summary
1 package WWW::Scripter::WindowGroup;
2  
3 2 $VERSION = '0.030'; # update POD, too
4  
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use WWW'Scripter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub new {
9 2 ▶ my(undef,%args) = @_;
Subroutine new: called CC=2 SCAR=9.2
Pod documented
10 2 ▶ if($args{empty}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'empty'}) { } 0 2 2
11 0 bless [],shift
12 }
13 else {
14 2 my $self = bless [my $w = new WWW'Scripter], shift;
15 0 $w->window_group($self);
16 0 $self;
17 }
18 }
19  
20 sub active_window {
21 0 ▶ return $_[0][0]
Subroutine active_window: not called CC=1 SCAR=6.9
Pod documented
22 }
23  
24 sub windows {
25 0 ▶ @{$_[0]}
Subroutine windows: not called CC=1 SCAR=6.9
Pod documented
26 }
27  
28 sub new_window {
29 unshift
30 0 ▶ @{$_[0]},
Branch: 1 branch
BranchTrueFalseTotal
$_[0][0] ? : 0 0 0
31 0 ▶ my $w = $_[0][0] ? clear_history{clone{$_[0][0]}}1 : new WWW'Scripter;
Subroutine new_window: not called CC=2 SCAR=17.9
Pod documented
32 0 $w->window_group($_[0]);
33 0 $w
34 }
35  
36 sub detach {
37 0 ▶ my $self = shift;
Subroutine detach: not called CC=3 SCAR=24.8
Pod documented
38 0 my $inddx = 0;
39 0 for(@$self) {
40 0 ▶ $_ == $_[0]
Branch: 1 branch
BranchTrueFalseTotal
$_ == $_[0] and splice(@$self, $inddx, 1), $_->window_group(undef), return 0 0 0
41 and splice(@$self, $inddx, 1), $_->window_group(undef),return;
42 0 ++$inddx
43 }
44 0 croak "detach cannot find $_[0] in $self";
45 }
46  
47 sub bring_to_front {
48 0 ▶ my $self = shift;
Subroutine bring_to_front: not called CC=3 SCAR=24.8
Pod documented
49 0 my $inddx = 0;
50 0 for(@$self) {
51 0 ▶ $_ == $_[0] and splice(@$self, $inddx, 1), unshift(@$self,$_), return;
Branch: 1 branch
BranchTrueFalseTotal
$_ == $_[0] and splice(@$self, $inddx, 1), unshift(@$self, $_), return 0 0 0
52 0 ++$inddx
53 }
54 0 croak "bring_to_front cannot find $_[0] in $self";
55 }
56  
57 sub attach {
58 0 ▶ unshift @{$_[0]}, $_[1];
Subroutine attach: not called CC=1 SCAR=6.9
Pod documented
59 0 $_[1]->window_group($_[0]);
60 _:
61 }
62  
63 =head1 NAME
64  
65 WWW::Scripter::WindowGroup - Multiple-window browsing environment
66  
67 =head1 VERSION
68  
69 Version 0.030
70  
71 =head1 SYNOPSIS
72  
73 use WWW'Scripter'WindowGroup;
74
75 $browser = new WWW'Scripter'WindowGroup;
76 # This has one window already
77
78 # OR:
79
80 $browser = new WWW'Scripter'WindowGroup empty => 1;
81 $browser->attach($w = new WWW'Scripter);
82
83 $w = $browser->active_window;
84 $w->get('http://ghare.dr/');
85 $w->close;
86
87 $w = $browser->new_window;
88 @w = $browser->windows;
89  
90 =head1 DESCRIPTION
91  
92 This module provides a virtual multiple-window browsing environment for
93 L<WWW::Scripter>. It does not actually create any windows on the screen,
94 but
95 it can be used to script websites that make use of multiple windows. The
96 individual windows themselves are WWW::Scripter objects.
97  
98 Before you start using this, consider whether the site you are scripting
99 actually I<needs> multiple windows. If a single-window environment will do,
100 use L<WWW::Scripter> directly.
101  
102 Note: Window groups hold strong references to their windows, but the
103 windows themselves hold weak references to the window group. So if you let
104 a window group go out of scope while retaining a reference to a window,
105 that window will revert to single-window mode.
106  
107 =head1 METHODS
108  
109 =over
110  
111 =item new
112  
113 The constructor. Call this method on the class, not on an object thereof.
114 It takes no arguments.
115  
116 =item active_window
117  
118 Returns the window that is currently 'active'. This can be changed by
119 scripts calling the C<focus> method on a window, or opening a new one, so
120 keep your own
121 reference to it if you need to refer to a specific window repeatedly.
122  
123 =item windows
124  
125 Returns a list of all windows in list context, or the number of windows in
126 scalar context.
127  
128 =item new_window
129  
130 Adds a new WWW::Scripter to the window group and returns it.
131  
132 =item attach ($window)
133  
134 This methods adds a window to the group, making it the frontmost window and
135 setting its C<window_group>
136 attribute appropriately.
137  
138 If you attach a window that is already attached to another group, strange
139 things may happen. Detach it first.
140  
141 =item detach ($window)
142  
143 This removes the window from the group and sets its C<window_group>
144 attribute to C<undef>. This is used internally by
145 WWW::Scripter's C<close> method.
146  
147 =item bring_to_front ($window)
148  
149 This makes C<$window> the active window.
150  
151 =back
152  
153 =head1 AUTHOR & COPYRIGHT
154  
155 See L<WWW::Scripter>
156  
157 =head1 SEE ALSO
158  
159 =over 4
160  
161 =item -
162  
163 L<WWW::Scripter>
164  
165 =back
« Scripter.pm ↑ Summary