1Mojo::Content::Single(3U)ser Contributed Perl DocumentatiMoonjo::Content::Single(3)
2
3
4

NAME

6       Mojo::Content::Single - HTTP content
7

SYNOPSIS

9         use Mojo::Content::Single;
10
11         my $single = Mojo::Content::Single->new;
12         $single->parse("Content-Length: 12\x0d\x0a\x0d\x0aHello World!");
13         say $single->headers->content_length;
14

DESCRIPTION

16       Mojo::Content::Single is a container for HTTP content, based on RFC
17       7230 <https://tools.ietf.org/html/rfc7230> and RFC 7231
18       <https://tools.ietf.org/html/rfc7231>.
19

EVENTS

21       Mojo::Content::Single inherits all events from Mojo::Content and can
22       emit the following new ones.
23
24   upgrade
25         $single->on(upgrade => sub ($single, $multi) {...});
26
27       Emitted when content gets upgraded to a Mojo::Content::MultiPart
28       object.
29
30         $single->on(upgrade => sub ($single, $multi) {
31           return unless $multi->headers->content_type =~ /multipart\/([^;]+)/i;
32           say "Multipart: $1";
33         });
34

ATTRIBUTES

36       Mojo::Content::Single inherits all attributes from Mojo::Content and
37       implements the following new ones.
38
39   asset
40         my $asset = $single->asset;
41         $single   = $single->asset(Mojo::Asset::Memory->new);
42
43       The actual content, defaults to a Mojo::Asset::Memory object with
44       "auto_upgrade" in Mojo::Asset::Memory enabled.
45
46   auto_upgrade
47         my $bool = $single->auto_upgrade;
48         $single  = $single->auto_upgrade($bool);
49
50       Try to detect multipart content and automatically upgrade to a
51       Mojo::Content::MultiPart object, defaults to a true value.
52

METHODS

54       Mojo::Content::Single inherits all methods from Mojo::Content and
55       implements the following new ones.
56
57   body_contains
58         my $bool = $single->body_contains('1234567');
59
60       Check if content contains a specific string.
61
62   body_size
63         my $size = $single->body_size;
64
65       Content size in bytes.
66
67   clone
68         my $clone = $single->clone;
69
70       Return a new Mojo::Content::Single object cloned from this content if
71       possible, otherwise return "undef".
72
73   get_body_chunk
74         my $bytes = $single->get_body_chunk(0);
75
76       Get a chunk of content starting from a specific position. Note that it
77       might not be possible to get the same chunk twice if content was
78       generated dynamically.
79
80   new
81         my $single = Mojo::Content::Single->new;
82         my $single = Mojo::Content::Single->new(asset => Mojo::Asset::File->new);
83         my $single = Mojo::Content::Single->new({asset => Mojo::Asset::File->new});
84
85       Construct a new Mojo::Content::Single object and subscribe to event
86       "read" in Mojo::Content with default content parser.
87
88   parse
89         $single = $single->parse("Content-Length: 12\x0d\x0a\x0d\x0aHello World!");
90         my $multi = $single->parse("Content-Type: multipart/form-data\x0d\x0a\x0d\x0a");
91
92       Parse content chunk and upgrade to Mojo::Content::MultiPart object if
93       necessary.
94

SEE ALSO

96       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
97
98
99
100perl v5.38.0                      2023-09-11          Mojo::Content::Single(3)
Impressum