CGI::Test::Page(3pm)

πŸ“¦
version 1.111 Β· 2 versions
  • 1.111 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.111 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– CGI::Test::Page πŸ’–

ok bestie, gather round, because we're diving into CGI::Test::Page(3pm) β€” that's a User Contributed Perl Documentation page, and yes it's giving ✨abstract HTTP reply content✨ energy. Let's go πŸŽ€


🌸 NAME 🌸

CGI::Test::Page β€” the abstract represention of an HTTP reply content

(yes, "represention". We keep it. We respect the original spelling, no cap πŸ’…)


✨ SYNOPSIS ✨

# Deferred class, only heirs can be created
# $page holds a CGI::Test::Page object

use CGI::Test;

ok 1, $page->is_ok;
ok 2, $page->user ne '';    # authenticated access

my $ctype = $page->content_type;
ok 3, $ctype eq "text/plain";

$page->delete;

πŸ¦‹ DESCRIPTION πŸ¦‹

So the tea is: CGI::Test::Page is a deferred class. Like, it's the blueprint, not the building. It's an abstract representation of an HTTP reply content β€” the kind of thing that would show up in a browser as a page β€” but heads up, it doesn't necessarily hold HTML content. It could be anything, okay? Don't assume πŸ’€

Here's the class hierarchy tree, and I've stripped the leading CGI::Test:: string off for readability, with a trailing * marking the deferred classes:

Page*
  Page::Error
  Page::Real*
    Page::HTML
    Page::Other
    Page::Text

Those classes get constructed as needed by CGI::Test. And listen β€” you must always call delete on them to break the circular references, if you care about reclaiming unused memory. Which you should, bestie. Memory leaks are not the vibe. 😭


πŸ‘‘ INTERFACE πŸ‘‘

This is the interface defined right here at the CGI::Test::Page level. Each subclass may add further specific features, but the following is available to the whole entire hierarchy, periodt:

  • content_type β€” the MIME content type, along with parameters, exactly as it appeared in the headers. For instance, it can be:
text/html; charset=ISO-8859-1

Don't you dare assume it's just text/html though. Use something like:

ok 1, $page->content_type =~ m|^text/html\b|;

in your regression tests, which will match whether there are parameters following the content type or not. Slay πŸ’…

  • delete β€” breaks circular references to allow proper reclaiming of unused memory. This must be the last thing you call on the object before you forget about it. Like, the final farewell. 🫢
  • error_code β€” the error code. It'll be 0 to mean OK, but otherwise HTTP error codes are used, as described by HTTP::Status.
  • forms β€” returns a list reference containing all the CGI forms on the page, as CGI::Test::Form objects. It will be an empty list for anything but CGI::Test::Page::HTML, naturally. 😌
  • form_count β€” the amount of forms held in the forms list.
  • is_error β€” returns true when the page indicates an HTTP error.
  • is_ok β€” returns true when the page is not the result of an HTTP error.
  • server β€” returns the server object that returned the page. Currently, this is the CGI::Test object, but it might change one day. In any case, this is the place where GET/POST requests may be addresed. (Another original spelling! We stan consistency πŸ’–)
  • user β€” the authenticated user that requested this page, or undef if no authentication was made.

πŸ’œ AUTHORS πŸ’œ

The original author is Raphael Manfredi.

Steven Hilton was long time maintainer of this module.

Current maintainer is Alexander Tokarev <tokarev@cpan.org>. πŸ’Œ


🌈 SEE ALSO 🌈


And that's the whole page, bestie! This little legend came from perl v5.34.0 and it's dated 2022-06-10. Go forth, call delete, reclaim your memory, and be the main character of your own test suite 🧚✨πŸ’