.\" 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 "2013-04-21" "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 content base class .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& package Mojo::Content::MyContent; \& use Mojo::Base \*(AqMojo::Content\*(Aq; \& \& sub body_contains {...} \& sub body_size {...} \& sub get_body_chunk {...} .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Content is an abstract base class for \s-1HTTP\s0 content as described in \&\s-1RFC\s0 2616. .SH "EVENTS" .IX Header "EVENTS" Mojo::Content inherits all events from Mojo::EventEmitter and can emit the following new ones. .SS "body" .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 .SS "drain" .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 .SS "read" .IX Subsection "read" .Vb 4 \& $content\->on(read => sub { \& my ($content, $bytes) = @_; \& ... \& }); .Ve .PP Emitted when a new chunk of content arrives. .PP .Vb 5 \& $content\->unsubscribe(\*(Aqread\*(Aq); \& $content\->on(read => sub { \& my ($content, $bytes) = @_; \& say "Streaming: $bytes"; \& }); .Ve .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::Content implements the following attributes. .SS "auto_relax" .IX Subsection "auto_relax" .Vb 2 \& my $relax = $content\->auto_relax; \& $content = $content\->auto_relax(1); .Ve .PP Try to detect when relaxed parsing is necessary. .SS "headers" .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. .SS "max_buffer_size" .IX Subsection "max_buffer_size" .Vb 2 \& my $size = $content\->max_buffer_size; \& $content = $content\->max_buffer_size(1024); .Ve .PP Maximum size in bytes of buffer for content parser, defaults to the value of the \s-1MOJO_MAX_BUFFER_SIZE\s0 environment variable or \f(CW262144\fR. .SS "max_leftover_size" .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 \s-1MOJO_MAX_LEFTOVER_SIZE\s0 environment variable or \f(CW262144\fR. .SS "relaxed" .IX Subsection "relaxed" .Vb 2 \& my $relaxed = $content\->relaxed; \& $content = $content\->relaxed(1); .Ve .PP Activate relaxed parsing for responses that are terminated with a connection close. .SS "skip_body" .IX Subsection "skip_body" .Vb 2 \& my $skip = $content\->skip_body; \& $content = $content\->skip_body(1); .Ve .PP Skip body parsing and finish after headers. .SH "METHODS" .IX Header "METHODS" Mojo::Content inherits all methods from Mojo::EventEmitter and implements the following new ones. .SS "body_contains" .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. .SS "body_size" .IX Subsection "body_size" .Vb 1 \& my $size = $content\->body_size; .Ve .PP Content size in bytes. Meant to be overloaded in a subclass. .SS "boundary" .IX Subsection "boundary" .Vb 1 \& my $boundary = $content\->boundary; .Ve .PP Extract multipart boundary from \f(CW\*(C`Content\-Type\*(C'\fR header. .SS "build_body" .IX Subsection "build_body" .Vb 1 \& my $string = $content\->build_body; .Ve .PP Render whole body. .SS "build_headers" .IX Subsection "build_headers" .Vb 1 \& my $string = $content\->build_headers; .Ve .PP Render all headers. .SS "charset" .IX Subsection "charset" .Vb 1 \& my $charset = $content\->charset; .Ve .PP Extract charset from \f(CW\*(C`Content\-Type\*(C'\fR header. .SS "clone" .IX Subsection "clone" .Vb 1 \& my $clone = $content\->clone; .Ve .PP Clone content if possible, otherwise return \f(CW\*(C`undef\*(C'\fR. .SS "generate_body_chunk" .IX Subsection "generate_body_chunk" .Vb 1 \& my $bytes = $content\->generate_body_chunk(0); .Ve .PP Generate dynamic content. .SS "get_body_chunk" .IX Subsection "get_body_chunk" .Vb 1 \& my $bytes = $content\->get_body_chunk(0); .Ve .PP Get a chunk of content starting from a specfic position. Meant to be overloaded in a subclass. .SS "get_header_chunk" .IX Subsection "get_header_chunk" .Vb 1 \& my $bytes = $content\->get_header_chunk(13); .Ve .PP Get a chunk of the headers starting from a specfic position. .SS "has_leftovers" .IX Subsection "has_leftovers" .Vb 1 \& my $success = $content\->has_leftovers; .Ve .PP Check if there are leftovers. .SS "header_size" .IX Subsection "header_size" .Vb 1 \& my $size = $content\->header_size; .Ve .PP Size of headers in bytes. .SS "is_chunked" .IX Subsection "is_chunked" .Vb 1 \& my $success = $content\->is_chunked; .Ve .PP Check if content is chunked. .SS "is_compressed" .IX Subsection "is_compressed" .Vb 1 \& my $success = $content\->is_compressed; .Ve .PP Check if content is \f(CW\*(C`gzip\*(C'\fR compressed. .SS "is_dynamic" .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. .SS "is_finished" .IX Subsection "is_finished" .Vb 1 \& my $success = $content\->is_finished; .Ve .PP Check if parser is finished. .SS "is_limit_exceeded" .IX Subsection "is_limit_exceeded" .Vb 1 \& my $success = $content\->is_limit_exceeded; .Ve .PP Check if buffer has exceeded \f(CW\*(C`max_buffer_size\*(C'\fR. .SS "is_multipart" .IX Subsection "is_multipart" .Vb 1 \& my $false = $content\->is_multipart; .Ve .PP False. .SS "is_parsing_body" .IX Subsection "is_parsing_body" .Vb 1 \& my $success = $content\->is_parsing_body; .Ve .PP Check if body parsing started yet. .SS "leftovers" .IX Subsection "leftovers" .Vb 1 \& my $bytes = $content\->leftovers; .Ve .PP Get leftover data from content parser. .SS "parse" .IX Subsection "parse" .Vb 2 \& $content \& = $content\->parse("Content\-Length: 12\ex0d\ex0a\ex0d\ex0aHello World!"); .Ve .PP Parse content chunk. .SS "parse_body" .IX Subsection "parse_body" .Vb 1 \& $content = $content\->parse_body(\*(AqHi!\*(Aq); .Ve .PP Parse body chunk and skip headers. .SS "progress" .IX Subsection "progress" .Vb 1 \& my $size = $content\->progress; .Ve .PP Size of content already received from message in bytes. .SS "write" .IX Subsection "write" .Vb 2 \& $content = $content\->write($bytes); \& $content = $content\->write($bytes => sub {...}); .Ve .PP Write dynamic content non-blocking, the optional drain callback will be invoked once all data has been written. .SS "write_chunk" .IX Subsection "write_chunk" .Vb 2 \& $content = $content\->write_chunk($bytes); \& $content = $content\->write_chunk($bytes => 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, .