File Coverage

blib/lib/Selenium/Subclass.pm
Criterion Covered Total %
statement 14 59 23.7
branch 0 18 0.0
condition n/a
subroutine 5 10 50.0
pod 1 1 100.0
total 20 88 22.7


line stmt bran cond sub pod time code
1             package Selenium::Subclass;
2             $Selenium::Subclass::VERSION = '2.01';
3             #ABSTRACT: Generic template for Selenium sugar subclasses like Selenium::Session
4              
5 3     3   253734 use strict;
  3         7  
  3         111  
6 3     3   13 use warnings;
  3         6  
  3         230  
7              
8 3     3   40 use v5.28;
  3         9  
9              
10 3     3   12 no warnings 'experimental';
  3         21  
  3         131  
11 3     3   14 use feature qw/signatures/;
  3         4  
  3         2647  
12              
13              
14 0     0 1   sub new ( $class, $parent, $data ) {
  0            
  0            
  0            
  0            
15 0           my %lowkey;
16 0           @lowkey{ map { lc $_ } keys(%$data) } = values(%$data);
  0            
17 0           $lowkey{parent} = $parent;
18              
19 0           my $self = bless( \%lowkey, $class );
20              
21 0           $self->_build_subs($class);
22              
23             # Make sure this is set so we can expose it for use it in various other calls by end-users
24 0 0         if ( $self->{sortfield} eq 'element-6066-11e4-a52e-4f735466cecf' ) {
25 0           $self->{sortfield} = 'elementid';
26 0           $self->{elementid} = delete $self->{'element-6066-11e4-a52e-4f735466cecf'};
27             }
28              
29 0           return $self;
30             }
31              
32 0     0     sub _request ( $self, $method, %params ) {
  0            
  0            
  0            
  0            
33              
34             #XXX BAD SPEC AUTHOR, BAD!
35 0 0         if ( $self->{sortfield} eq 'elementid' ) {
36              
37             # Ensure element childs don't think they are their parent
38 0           $self->{to_inject}{elementid} = $self->{elementid};
39             }
40              
41             # Inject our sortField param, and anything else we need to
42 0           $params{ $self->{sortfield} } = $self->{ $self->{sortfield} };
43 0           my $inject = $self->{to_inject};
44 0 0         @params{ keys(%$inject) } = values(%$inject) if ref $inject eq 'HASH';
45              
46             # and ensure it is injected into child object requests
47             # This is primarily to ensure that the session ID trickles down correctly.
48             # Some also need the element ID to trickle down.
49             # However, in the case of getting child elements, we wish to specifically prevent that, and do so above.
50 0           $params{inject} = $self->{sortfield};
51              
52 0 0         $self->{callback}->( $self, $method, %params ) if $self->{callback};
53              
54 0           return $self->{parent}->_request( $method, %params );
55             }
56              
57 0     0     sub DESTROY ($self) {
  0            
  0            
58 0 0         return if ${^GLOBAL_PHASE} eq 'DESTRUCT';
59 0 0         $self->{destroy_callback}->($self) if $self->{destroy_callback};
60             }
61              
62             #TODO filter spec so we don't need parent anymore, and can have a catalog() method
63 0     0     sub _build_subs ( $self, $class ) {
  0            
  0            
  0            
64              
65             #Filter everything out which doesn't have {sortField} in URI
66 0           my $k = lc( $self->{sortfield} );
67              
68             #XXX deranged field name
69 0 0         $k = 'elementid' if $self->{sortfield} eq 'element-6066-11e4-a52e-4f735466cecf';
70              
71 0           foreach my $sub ( keys( %{ $self->{parent}{spec} } ) ) {
  0            
72 0 0         next unless $self->{parent}{spec}{$sub}{uri} =~ m/{\Q$k\E}/;
73             Sub::Install::install_sub(
74             {
75             code => sub {
76 0     0     my $self = shift;
77 0           return $self->_request( $sub, @_ );
78             },
79 0 0         as => $sub,
80             into => $class,
81             }
82             ) unless $class->can($sub);
83             }
84             }
85              
86             1;
87              
88             __END__
89              
90             =pod
91              
92             =encoding UTF-8
93              
94             =head1 NAME
95              
96             Selenium::Subclass - Generic template for Selenium sugar subclasses like Selenium::Session
97              
98             =head1 VERSION
99              
100             version 2.01
101              
102             =head1 CONSTRUCTOR
103              
104             =head2 $class->new($parent Selenium::Client, $data HASHREF)
105              
106             You should probably not use this directly; objects should be created as part of normal operation.
107              
108             =head1 SEE ALSO
109              
110             Please see those modules/websites for more information related to this module.
111              
112             =over 4
113              
114             =item *
115              
116             L<Selenium::Client|Selenium::Client>
117              
118             =back
119              
120             =head1 BUGS
121              
122             Please report any bugs or feature requests on the bugtracker website
123             L<https://github.com/troglodyne-internet-widgets/selenium-client-perl/issues>
124              
125             When submitting a bug or request, please include a test-file or a
126             patch to an existing test-file that illustrates the bug or desired
127             feature.
128              
129             =head1 AUTHORS
130              
131             Current Maintainers:
132              
133             =over 4
134              
135             =item *
136              
137             George S. Baugh <george@troglodyne.net>
138              
139             =back
140              
141             =head1 COPYRIGHT AND LICENSE
142              
143             Copyright (c) 2024 Troglodyne LLC
144              
145              
146             Permission is hereby granted, free of charge, to any person obtaining a copy
147             of this software and associated documentation files (the "Software"), to deal
148             in the Software without restriction, including without limitation the rights
149             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
150             copies of the Software, and to permit persons to whom the Software is
151             furnished to do so, subject to the following conditions:
152             The above copyright notice and this permission notice shall be included in all
153             copies or substantial portions of the Software.
154             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
155             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
156             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
157             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
158             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
159             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
160             SOFTWARE.
161              
162             =cut