| 1 | package Selenium::Subclass; | ||||||||||
| 2 | 3 | $Selenium::Subclass::VERSION = '2.01'; | |||||||||
| 3 | #ABSTRACT: Generic template for Selenium sugar subclasses like Selenium::Session | ||||||||||
| 4 | |||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use v5.28; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | ▶ | no warnings 'experimental'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 3 | ▶ | use feature qw/signatures/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | 0 | ▶ | 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 | 0 | ▶ | 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 | |||||||||||
| 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 | ▶ | @params{ keys(%$inject) } = values(%$inject) if ref $inject eq 'HASH'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | $self->{callback}->( $self, $method, %params ) if $self->{callback}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | |||||||||||
| 54 | 0 | return $self->{parent}->_request( $method, %params ); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub DESTROY ($self) { | ||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||
| 58 | 0 | ▶ | return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | ▶ | $self->{destroy_callback}->($self) if $self->{destroy_callback}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | #TODO filter spec so we don't need parent anymore, and can have a catalog() method | ||||||||||
| 63 | 0 | ▶ | sub _build_subs ( $self, $class ) { | ||||||||
|
Subroutine
_build_subs: not called CC=5 SCAR=34.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 | ▶ | $k = 'elementid' if $self->{sortfield} eq 'element-6066-11e4-a52e-4f735466cecf'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | |||||||||||
| 71 | 0 | foreach my $sub ( keys( %{ $self->{parent}{spec} } ) ) { | |||||||||
| 72 | 0 | ▶ | next unless $self->{parent}{spec}{$sub}{uri} =~ m/{\Q$k\E}/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | Sub::Install::install_sub( | ||||||||||
| 74 | { | ||||||||||
| 75 | 0 | ▶ | code => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 76 | 0 | my $self = shift; | |||||||||
| 77 | 0 | return $self->_request( $sub, @_ ); | |||||||||
| 78 | }, | ||||||||||
| 79 | 0 | ▶ | as => $sub, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | into => $class, | ||||||||||
| 81 | } | ||||||||||
| 82 | ) unless $class->can($sub); | ||||||||||
| 83 | } | ||||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 3 | 1; | |||||||||
| 87 | |||||||||||
| 88 | __END__ | ||||||||||