| 1 | # MIT License | ||
| 2 | # | ||
| 3 | # Copyright (c) 2026 Rawley Fowler <rawleyfowler@proton.me> | ||
| 4 | # | ||
| 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 6 | # of this software and associated documentation files (the "Software"), to deal | ||
| 7 | # in the Software without restriction, including without limitation the rights | ||
| 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 9 | # copies of the Software, and to permit persons to whom the Software is | ||
| 10 | # furnished to do so, subject to the following conditions: | ||
| 11 | # | ||
| 12 | # The above copyright notice and this permission notice shall be included in all | ||
| 13 | # copies or substantial portions of the Software. | ||
| 14 | # | ||
| 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 21 | # SOFTWARE. | ||
| 22 | |||
| 23 | package HTML::Composer::Unsafe; | ||
| 24 | |||
| 25 | =head1 NAME | ||
| 26 | |||
| 27 | HTML::Composer::Unsafe - Wrapper for Unsafe text in HTML::Composer, typically created via an HTML::Composer instance. | ||
| 28 | These objects aren't escaped by HTML::Composer when JSON is rendered. | ||
| 29 | |||
| 30 | =head1 SYNOPSIS | ||
| 31 | |||
| 32 | use HTML::Composer; | ||
| 33 | |||
| 34 | my $h = HTML::Composer->new; | ||
| 35 | my $unsafe_text = $h->unsafe(q[document.body.addEventListener('htmx:configRequest', (event) => {})]); | ||
| 36 | |||
| 37 | ref($unsafe_text) # HTML::Composer::Unsafe | ||
| 38 | |||
| 39 | my $html = $h->html([ | ||
| 40 | head => [ | ||
| 41 | title => ["My Site!"], | ||
| 42 | script => [$unsafe_text] | ||
| 43 | ], | ||
| 44 | body => [ | ||
| 45 | div => [ | ||
| 46 | "Hello World!" | ||
| 47 | ] | ||
| 48 | ] | ||
| 49 | ]); | ||
| 50 | |||
| 51 | =cut | ||
| 52 | |||
| 53 | 8 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 54 | 8 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 55 | |||
| 56 | 8 | ▶ | use overload '""' => \&to_string; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 57 | |||
| 58 | 3 | ▶ | sub new { |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 59 | 3 | my ( $class, $str ) = @_; | |
| 60 | 3 | return bless { str => $str }, $class; | |
| 61 | } | ||
| 62 | |||
| 63 | 4 | ▶ | sub to_string { |
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 64 | 4 | return shift->{str}; | |
| 65 | } | ||
| 66 | |||
| 67 | 8 | 1; | |