| 1 | package Selenium::Subclass; | ||||||||||
| 2 | 2 | $Selenium::Subclass::VERSION = '1.06'; | |||||||||
| 3 | #ABSTRACT: Generic template for Selenium sugar subclasses like Selenium::Session | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use v5.28; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | no warnings 'experimental'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use feature qw/signatures/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | ▶ | sub new ($class,$parent,$data) { | |||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 15 | 0 | my %lowkey; | |||||||||
| 16 | 0 | @lowkey{map { lc $_ } keys(%$data)} = values(%$data); | |||||||||
| 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 | ▶ | if ( $self->{sortfield} eq 'element-6066-11e4-a52e-4f735466cecf') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | sub _request ($self, $method, %params) { | |||||||||
|
Subroutine
_request: not called CC=4 SCAR=30.0
| |||||||||||
| 33 | |||||||||||
| 34 | #XXX BAD SPEC AUTHOR, BAD! | ||||||||||
| 35 | 0 | ▶ | if ( $self->{sortfield} eq 'elementid') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | # Ensure element childs don't think they are their parent | ||||||||||
| 37 | 0 | $self->{to_inject}{elementid} = $self->{elementid}; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | # Inject our sortField param, and anything else we need to | ||||||||||
| 41 | 0 | $params{$self->{sortfield}} = $self->{$self->{sortfield}}; | |||||||||
| 42 | 0 | my $inject = $self->{to_inject}; | |||||||||
| 43 | 0 | ▶ | @params{keys(%$inject)} = values(%$inject) if ref $inject eq 'HASH'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | |||||||||||
| 45 | # and ensure it is injected into child object requests | ||||||||||
| 46 | # This is primarily to ensure that the session ID trickles down correctly. | ||||||||||
| 47 | # Some also need the element ID to trickle down. | ||||||||||
| 48 | # However, in the case of getting child elements, we wish to specifically prevent that, and do so above. | ||||||||||
| 49 | 0 | $params{inject} = $self->{sortfield}; | |||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | $self->{callback}->($self,$method,%params) if $self->{callback}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | 0 | return $self->{parent}->_request($method, %params); | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | ▶ | sub DESTROY($self) { | |||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||
| 57 | 0 | ▶ | return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | ▶ | $self->{destroy_callback}->($self) if $self->{destroy_callback}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | #TODO filter spec so we don't need parent anymore, and can have a catalog() method | ||||||||||
| 62 | ▶ | sub _build_subs($self,$class) { | |||||||||
|
Subroutine
_build_subs: not called CC=5 SCAR=34.0
| |||||||||||
| 63 | #Filter everything out which doesn't have {sortField} in URI | ||||||||||
| 64 | 0 | my $k = lc($self->{sortfield}); | |||||||||
| 65 | |||||||||||
| 66 | #XXX deranged field name | ||||||||||
| 67 | 0 | ▶ | $k = 'elementid' if $self->{sortfield} eq 'element-6066-11e4-a52e-4f735466cecf'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | |||||||||||
| 69 | 0 | foreach my $sub (keys(%{$self->{parent}{spec}})) { | |||||||||
| 70 | 0 | ▶ | next unless $self->{parent}{spec}{$sub}{uri} =~ m/{\Q$k\E}/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | Sub::Install::install_sub( | ||||||||||
| 72 | { | ||||||||||
| 73 | code => sub { | ||||||||||
| 74 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 75 | 0 | return $self->_request($sub,@_); | |||||||||
| 76 | }, | ||||||||||
| 77 | 0 | ▶ | as => $sub, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | into => $class, | ||||||||||
| 79 | } | ||||||||||
| 80 | ) unless $class->can($sub); | ||||||||||
| 81 | } | ||||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 2 | 1; | |||||||||
| 85 | |||||||||||
| 86 | __END__ | ||||||||||
| 87 | |||||||||||
| 88 | =pod | ||||||||||
| 89 | |||||||||||
| 90 | =encoding UTF-8 | ||||||||||
| 91 | |||||||||||
| 92 | =head1 NAME | ||||||||||
| 93 | |||||||||||
| 94 | Selenium::Subclass - Generic template for Selenium sugar subclasses like Selenium::Session | ||||||||||
| 95 | |||||||||||
| 96 | =head1 VERSION | ||||||||||
| 97 | |||||||||||
| 98 | version 1.06 | ||||||||||
| 99 | |||||||||||
| 100 | =head1 CONSTRUCTOR | ||||||||||
| 101 | |||||||||||
| 102 | =head2 $class->new($parent Selenium::Client, $data HASHREF) | ||||||||||
| 103 | |||||||||||
| 104 | You should probably not use this directly; objects should be created as part of normal operation. | ||||||||||
| 105 | |||||||||||
| 106 | =head1 AUTHOR | ||||||||||
| 107 | |||||||||||
| 108 | George S. Baugh <george@troglodyne.net> | ||||||||||
| 109 | |||||||||||
| 110 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 111 | |||||||||||
| 112 | This software is Copyright (c) 2023 by George S. Baugh. | ||||||||||
| 113 | |||||||||||
| 114 | This is free software, licensed under: | ||||||||||
| 115 | |||||||||||
| 116 | The MIT (X11) License | ||||||||||
| 117 | |||||||||||
| 118 | =cut | ||||||||||