.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Mojo::Content 3pm" .TH Mojo::Content 3pm "2012-09-05" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojo::Content \- HTTP 1.1 content base class .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Base \*(AqMojo::Content\*(Aq; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Content is an abstract base class for \s-1HTTP\s0 1.1 content as described in \s-1RFC\s0 2616. .SH "EVENTS" .IX Header "EVENTS" Mojo::Content can emit the following events. .ie n .SS """drain""" .el .SS "\f(CWdrain\fP" .IX Subsection "drain" .Vb 4 \& $content\->on(drain => sub { \& my ($content, $offset) = @_; \& ... \& }); .Ve .PP Emitted once all data has been written. .PP .Vb 4 \& $content\->on(drain => sub { \& my $content = shift; \& $content\->write_chunk(time); \& }); .Ve .ie n .SS """body""" .el .SS "\f(CWbody\fP" .IX Subsection "body" .Vb 4 \& $content\->on(body => sub { \& my $content = shift; \& ... \& }); .Ve .PP Emitted once all headers have been parsed and the body starts. .PP .Vb 4 \& $content\->on(body => sub { \& my $content = shift; \& $content\->auto_upgrade(0) if $content\->headers\->header(\*(AqX\-No\-MultiPart\*(Aq); \& }); .Ve .ie n .SS """read""" .el .SS "\f(CWread\fP" .IX Subsection "read" .Vb 4 \& $content\->on(read => sub { \& my ($content, $chunk) = @_; \& ... \& }); .Ve .PP Emitted when a new chunk of content arrives. .PP .Vb 5 \& $content\->unsubscribe(\*(Aqread\*(Aq); \& $content\->on(read => sub { \& my ($content, $chunk) = @_; \& say "Streaming: $chunk"; \& }); .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::Content implements the following attributes. .ie n .SS """auto_relax""" .el .SS "\f(CWauto_relax\fP" .IX Subsection "auto_relax" .Vb 2 \& my $relax = $content\->auto_relax; \& $content = $content\->auto_relax(1); .Ve .PP Try to detect broken web servers and turn on relaxed parsing automatically. .ie n .SS """headers""" .el .SS "\f(CWheaders\fP" .IX Subsection "headers" .Vb 2 \& my $headers = $content\->headers; \& $content = $content\->headers(Mojo::Headers\->new); .Ve .PP Content headers, defaults to a Mojo::Headers object. .ie n .SS """max_leftover_size""" .el .SS "\f(CWmax_leftover_size\fP" .IX Subsection "max_leftover_size" .Vb 2 \& my $size = $content\->max_leftover_size; \& $content = $content\->max_leftover_size(1024); .Ve .PP Maximum size in bytes of buffer for pipelined \s-1HTTP\s0 requests, defaults to the value of the \f(CW\*(C`MOJO_MAX_LEFTOVER_SIZE\*(C'\fR environment variable or \f(CW262144\fR. .ie n .SS """relaxed""" .el .SS "\f(CWrelaxed\fP" .IX Subsection "relaxed" .Vb 2 \& my $relaxed = $content\->relaxed; \& $content = $content\->relaxed(1); .Ve .PP Activate relaxed parsing for \s-1HTTP\s0 0.9 and responses that are terminated with a connection close. .SH "METHODS" .IX Header "METHODS" Mojo::Content inherits all methods from Mojo::EventEmitter and implements the following new ones. .ie n .SS """body_contains""" .el .SS "\f(CWbody_contains\fP" .IX Subsection "body_contains" .Vb 1 \& my $success = $content\->body_contains(\*(Aqfoo bar baz\*(Aq); .Ve .PP Check if content contains a specific string. Meant to be overloaded in a subclass. .ie n .SS """body_size""" .el .SS "\f(CWbody_size\fP" .IX Subsection "body_size" .Vb 1 \& my $size = $content\->body_size; .Ve .PP Content size in bytes. Meant to be overloaded in a subclass. .ie n .SS """boundary""" .el .SS "\f(CWboundary\fP" .IX Subsection "boundary" .Vb 1 \& my $boundary = $content\->boundary; .Ve .PP Extract multipart boundary from \f(CW\*(C`Content\-Type\*(C'\fR header. .ie n .SS """build_body""" .el .SS "\f(CWbuild_body\fP" .IX Subsection "build_body" .Vb 1 \& my $string = $content\->build_body; .Ve .PP Render whole body. .ie n .SS """build_headers""" .el .SS "\f(CWbuild_headers\fP" .IX Subsection "build_headers" .Vb 1 \& my $string = $content\->build_headers; .Ve .PP Render all headers. .ie n .SS """charset""" .el .SS "\f(CWcharset\fP" .IX Subsection "charset" .Vb 1 \& my $charset = $content\->charset; .Ve .PP Extract charset from \f(CW\*(C`Content\-Type\*(C'\fR header. .ie n .SS """clone""" .el .SS "\f(CWclone\fP" .IX Subsection "clone" .Vb 1 \& my $clone = $content\->clone; .Ve .PP Clone content if possible, otherwise return \f(CW\*(C`undef\*(C'\fR. .ie n .SS """generate_body_chunk""" .el .SS "\f(CWgenerate_body_chunk\fP" .IX Subsection "generate_body_chunk" .Vb 1 \& my $chunk = $content\->generate_body_chunk(0); .Ve .PP Generate dynamic content. .ie n .SS """get_body_chunk""" .el .SS "\f(CWget_body_chunk\fP" .IX Subsection "get_body_chunk" .Vb 1 \& my $chunk = $content\->get_body_chunk(0); .Ve .PP Get a chunk of content starting from a specfic position. Meant to be overloaded in a subclass. .ie n .SS """get_header_chunk""" .el .SS "\f(CWget_header_chunk\fP" .IX Subsection "get_header_chunk" .Vb 1 \& my $chunk = $content\->get_header_chunk(13); .Ve .PP Get a chunk of the headers starting from a specfic position. .ie n .SS """has_leftovers""" .el .SS "\f(CWhas_leftovers\fP" .IX Subsection "has_leftovers" .Vb 1 \& my $success = $content\->has_leftovers; .Ve .PP Check if there are leftovers. .ie n .SS """header_size""" .el .SS "\f(CWheader_size\fP" .IX Subsection "header_size" .Vb 1 \& my $size = $content\->header_size; .Ve .PP Size of headers in bytes. .ie n .SS """is_chunked""" .el .SS "\f(CWis_chunked\fP" .IX Subsection "is_chunked" .Vb 1 \& my $success = $content\->is_chunked; .Ve .PP Check if content is chunked. .ie n .SS """is_dynamic""" .el .SS "\f(CWis_dynamic\fP" .IX Subsection "is_dynamic" .Vb 1 \& my $success = $content\->is_dynamic; .Ve .PP Check if content will be dynamically generated, which prevents \f(CW\*(C`clone\*(C'\fR from working. .ie n .SS """is_finished""" .el .SS "\f(CWis_finished\fP" .IX Subsection "is_finished" .Vb 1 \& my $success = $content\->is_finished; .Ve .PP Check if parser is finished. .ie n .SS """is_multipart""" .el .SS "\f(CWis_multipart\fP" .IX Subsection "is_multipart" .Vb 1 \& my $false = $content\->is_multipart; .Ve .PP False. .ie n .SS """is_parsing_body""" .el .SS "\f(CWis_parsing_body\fP" .IX Subsection "is_parsing_body" .Vb 1 \& my $success = $content\->is_parsing_body; .Ve .PP Check if body parsing started yet. .ie n .SS """leftovers""" .el .SS "\f(CWleftovers\fP" .IX Subsection "leftovers" .Vb 1 \& my $bytes = $content\->leftovers; .Ve .PP Get leftover data from content parser. .ie n .SS """parse""" .el .SS "\f(CWparse\fP" .IX Subsection "parse" .Vb 1 \& $content = $content\->parse("Content\-Length: 12\er\en\er\enHello World!"); .Ve .PP Parse content chunk. .ie n .SS """parse_body""" .el .SS "\f(CWparse_body\fP" .IX Subsection "parse_body" .Vb 1 \& $content = $content\->parse_body("Hi!"); .Ve .PP Parse body chunk. .ie n .SS """parse_body_once""" .el .SS "\f(CWparse_body_once\fP" .IX Subsection "parse_body_once" .Vb 1 \& $content = $content\->parse_body_once("Hi!"); .Ve .PP Parse body chunk once. .ie n .SS """parse_until_body""" .el .SS "\f(CWparse_until_body\fP" .IX Subsection "parse_until_body" .Vb 2 \& $content \& = $content\->parse_until_body("Content\-Length: 12\er\en\er\enHello World!"); .Ve .PP Parse chunk and stop after headers. .ie n .SS """progress""" .el .SS "\f(CWprogress\fP" .IX Subsection "progress" .Vb 1 \& my $size = $content\->progress; .Ve .PP Size of content already received from message in bytes. .ie n .SS """write""" .el .SS "\f(CWwrite\fP" .IX Subsection "write" .Vb 2 \& $content\->write(\*(AqHello!\*(Aq); \& $content\->write(\*(AqHello!\*(Aq, sub {...}); .Ve .PP Write dynamic content non-blocking, the optional drain callback will be invoked once all data has been written. .ie n .SS """write_chunk""" .el .SS "\f(CWwrite_chunk\fP" .IX Subsection "write_chunk" .Vb 2 \& $content\->write_chunk(\*(AqHello!\*(Aq); \& $content\->write_chunk(\*(AqHello!\*(Aq, sub {...}); .Ve .PP Write dynamic content non-blocking with \f(CW\*(C`chunked\*(C'\fR transfer encoding, the optional drain callback will be invoked once all data has been written. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .