| 1 | package PAGI::FastAPI::Response::HTML; | ||
| 2 | |||
| 3 | 24 | ▶ | use v5.38; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 24 | ▶ | use experimental 'class'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 24 | ▶ | use version; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 24 | our $VERSION = qv('v1.7.3'); | |
| 8 | 24 | our $AUTHORITY = 'cpan:MANWAR'; | |
| 9 | |||
| 10 | 24 | ▶ | use Future::AsyncAwait; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 24 | ▶ | use PAGI::FastAPI::Response; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | 24 | class PAGI::FastAPI::Response::HTML :isa(PAGI::FastAPI::Response) { | |
| 14 | |||
| 15 | 5 | ▶ | method prepare_headers ($c, $default_content_type = 'text/html; charset=utf-8') { |
|
Subroutine
prepare_headers: called CC=2 SCAR=6.9
Pod
undocumented
| |||
| 16 | 5 | $self->SUPER::prepare_headers($c, 'text/html; charset=utf-8'); | |
| 17 | 24 | } | |
| 18 | |||
| 19 | 1 | ▶ | async method send ($c, $pagi_writer) { |
|
Subroutine
send: called CC=1 SCAR=0.0
Pod
documented
| |||
| 20 | 1 | $self->prepare_headers($c); | |
| 21 | 1 | await $pagi_writer->write($self->body); | |
| 22 | 24 | } | |
| 23 | } | ||
| 24 | |||
| 25 | 24 | ▶ | use overload '""' => sub { shift->body }, fallback => 1; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 26 | |||
| 27 | =encoding utf-8 | ||
| 28 | |||
| 29 | =head1 NAME | ||
| 30 | |||
| 31 | PAGI::FastAPI::Response::HTML - HTML Response Class for PAGI::FastAPI | ||
| 32 | |||
| 33 | =head1 VERSION | ||
| 34 | |||
| 35 | Version v1.7.3 | ||
| 36 | |||
| 37 | =head1 SYNOPSIS | ||
| 38 | |||
| 39 | use PAGI::FastAPI::Response::HTML; | ||
| 40 | |||
| 41 | # Direct construction | ||
| 42 | my $res = PAGI::FastAPI::Response::HTML->new( | ||
| 43 | body => '<h1>Hello World</h1>', | ||
| 44 | status => 200, | ||
| 45 | ); | ||
| 46 | |||
| 47 | # Or via Context helper method inside route handlers | ||
| 48 | $app->get('/', handler => async sub ($c) { | ||
| 49 | return $c->html('<h1>Welcome</h1>'); | ||
| 50 | }); | ||
| 51 | |||
| 52 | =head1 DESCRIPTION | ||
| 53 | |||
| 54 | C<PAGI::FastAPI::Response::HTML> handles HTTP responses with a C<Content-Type> of C<text/html; charset=utf-8>. | ||
| 55 | |||
| 56 | =head1 CONSTRUCTOR | ||
| 57 | |||
| 58 | =head2 C<new(%options)> | ||
| 59 | |||
| 60 | =over 4 | ||
| 61 | |||
| 62 | =item * C<body> (Optional) | ||
| 63 | |||
| 64 | The HTML string body. Defaults to an empty string. | ||
| 65 | |||
| 66 | =item * C<status> (Optional) | ||
| 67 | |||
| 68 | HTTP status code integer. Defaults to C<200>. | ||
| 69 | |||
| 70 | =item * C<headers> (Optional) | ||
| 71 | |||
| 72 | ArrayRef of additional header key-value pairs (e.g., C<< [ ['X-Frame-Options' => 'DENY'] ] >>). | ||
| 73 | |||
| 74 | =back | ||
| 75 | |||
| 76 | =head1 METHODS | ||
| 77 | |||
| 78 | =head2 C<send($c, $pagi_writer)> | ||
| 79 | |||
| 80 | Applies status code, sets the C<Content-Type> header to C<text/html; charset=utf-8>, and writes the HTML body string asynchronously to the response stream writer. | ||
| 81 | |||
| 82 | =head1 SEE ALSO | ||
| 83 | |||
| 84 | L<PAGI::FastAPI::Context>, L<PAGI::FastAPI> | ||
| 85 | |||
| 86 | =head1 AUTHOR | ||
| 87 | |||
| 88 | Mohammad Sajid Anwar, C<< <mohammad.anwar at yahoo.com> >> | ||
| 89 | |||
| 90 | =head1 REPOSITORY | ||
| 91 | |||
| 92 | L<https://github.com/manwar/PAGI-FastAPI> | ||
| 93 | |||
| 94 | =head1 BUGS | ||
| 95 | |||
| 96 | Please report any bugs or feature requests through the web interface at L<https://github.com/manwar/PAGI-FastAPI/issues>. | ||
| 97 | I will be notified and then you'll automatically be notified of progress on your | ||
| 98 | bug as I make changes. | ||
| 99 | |||
| 100 | =head1 SUPPORT | ||
| 101 | |||
| 102 | You can find documentation for this module with the perldoc command. | ||
| 103 | |||
| 104 | perldoc PAGI::FastAPI::Response::HTML | ||
| 105 | |||
| 106 | You can also look for information at: | ||
| 107 | |||
| 108 | =over 4 | ||
| 109 | |||
| 110 | =item * BUG Report | ||
| 111 | |||
| 112 | L<https://github.com/manwar/PAGI-FastAPI/issues> | ||
| 113 | |||
| 114 | =item * Search MetaCPAN | ||
| 115 | |||
| 116 | L<https://metacpan.org/dist/PAGI-FastAPI/> | ||
| 117 | |||
| 118 | =back | ||
| 119 | |||
| 120 | =head1 LICENSE AND COPYRIGHT | ||
| 121 | |||
| 122 | Copyright (C) 2026 Mohammad Sajid Anwar. | ||
| 123 | |||
| 124 | This program is free software; you can redistribute it and/or modify it under | ||
| 125 | the terms of the Artistic License (2.0). | ||
| 126 | |||
| 127 | =cut | ||
| 128 | |||
| 129 | 24 | 1; # End of PAGI::FastAPI::Response::HTML | |