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 <http://tools.ietf.org/html/rfc7230> and RFC 7231
18       <http://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 {
26           my ($single, $multi) = @_;
27           ...
28         });
29
30       Emitted when content gets upgraded to a Mojo::Content::MultiPart
31       object.
32
33         $single->on(upgrade => sub {
34           my ($single, $multi) = @_;
35           return unless $multi->headers->content_type =~ /multipart\/([^;]+)/i;
36           say "Multipart: $1";
37         });
38

ATTRIBUTES

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

METHODS

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

SEE ALSO

101       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
102
103
104
105perl v5.28.1                      2018-11-22          Mojo::Content::Single(3)
Impressum