From fbeba3e0c7cb53bce4302b4ac206a0f9b169d20f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 19 Aug 2012 09:57:45 -0500 Subject: add sugary constructor --- lib/Web/Response.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib') diff --git a/lib/Web/Response.pm b/lib/Web/Response.pm index 89c0e26..7ab39db 100644 --- a/lib/Web/Response.pm +++ b/lib/Web/Response.pm @@ -79,6 +79,25 @@ has _encoding_obj => ( }, ); +sub BUILDARGS { + my $class = shift; + + if (@_ == 1 && ref($_[0]) eq 'ARRAY') { + return { + status => $_[0][0], + (@{ $_[0] } > 1 + ? (headers => $_[0][1]) + : ()), + (@{ $_[0] } > 2 + ? (content => $_[0][2]) + : ()), + }; + } + else { + return $class->SUPER::BUILDARGS(@_); + } +} + sub redirect { my $self = shift; my ($url, $status) = @_; -- cgit v1.2.3-54-g00ecf