Response.pm 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 'Response' Class.
  16. See L<https://playwright.dev/#version=master&path=docs%2Fapi.md&q=class-response> 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::Response)
  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 {
  39. my $self = shift;
  40. $self->{browser}->_request( undef, args => [@_], command => $method, result => $self->{guid} );
  41. },
  42. as => $method,
  43. }) unless $self->can($method);
  44. }
  45. return ($self);
  46. }
  47. =head1 METHODS
  48. =head2 spec
  49. Return the relevant methods and their definitions for this module which are built dynamically from the Playwright API spec.
  50. =cut
  51. sub spec ($self) {
  52. return %{$self->{spec}};
  53. }
  54. 1;