Result.pm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package Playwright::Response;
  2. use strict;
  3. use warnings;
  4. use Sub::Install();
  5. use Carp qw{confess};
  6. #ABSTRACT: Object representing Playwright network responses
  7. no warnings 'experimental';
  8. use feature qw{signatures state};
  9. =head2 SYNOPSIS
  10. use Playwright;
  11. my ($browser,$page) = Playwright->new( browser => "chrome" );
  12. my $res = $page->goto('http://www.google.com');
  13. print $res->url;
  14. =head2 DESCRIPTION
  15. Perl interface to a lightweight node.js webserver that proxies commands runnable by Playwright in the 'Page' Class.
  16. See L<https://playwright.dev/#version=v1.5.1&path=docs%2Fapi.md&q=class-page> for more information.
  17. The specification for this class can also be inspected with the 'spec' method:
  18. use Data::Dumper;
  19. use Playwright::Response;
  20. my $page = Playwright::Response->new(...);
  21. print Dumper($page->spec);
  22. =head1 CONSTRUCTOR
  23. =head2 new(HASH) = (Playwright,Playwright::Frame)
  24. Creates a new page and returns a handle to interact with it, along with a Playwright::Frame (the main Frame) to interact with (supposing the page is a FrameSet).
  25. =head3 INPUT
  26. browser (Playwright) : Playwright object.
  27. page (STRING) : _guid returned by a response from the Playwright server with _type of 'Page'.
  28. =cut
  29. sub new ($class, %options) {
  30. my $self = bless({
  31. spec => $options{browser}{spec}{Response}{members},
  32. browser => $options{browser},
  33. guid => $options{id},
  34. }, $class);
  35. # Install the subroutines if they aren't already
  36. foreach my $method (keys(%{$self->{spec}})) {
  37. Sub::Install::install_sub({
  38. code => sub { _request(shift, undef, args => [@_], command => $method, result => $self->{guid} ) },
  39. as => $method,
  40. }) unless $self->can($method);
  41. }
  42. return ($self);
  43. }
  44. =head1 METHODS
  45. =head2 spec
  46. Return the relevant methods and their definitions for this module which are built dynamically from the Playwright API spec.
  47. =cut
  48. sub spec ($self) {
  49. return %{$self->{spec}};
  50. }
  51. sub _request ($self,$translator, %options) {
  52. $options{result} = $self->{guid};
  53. return $self->{browser}->_request($translator, %options);
  54. }
  55. 1;