{"id":120,"date":"2009-03-06T10:04:21","date_gmt":"2009-03-06T10:04:21","guid":{"rendered":"http:\/\/beta.robertprice.co.uk\/robblog\/2009\/03\/redirects_in_catalyst-shtml\/"},"modified":"2009-03-06T10:04:21","modified_gmt":"2009-03-06T10:04:21","slug":"redirects_in_catalyst-shtml","status":"publish","type":"post","link":"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/","title":{"rendered":"Redirects In Catalyst"},"content":{"rendered":"<p>\nI&#8217;ve been using <a href=\"http:\/\/www.catalystframework.org\/\">Catalyst<\/a> quite a bit recently. For those of you who don&#8217;t know what Catalyst is, the easiest buzzword compliant comparison is <a href=\"http:\/\/rubyonrails.org\/\">Ruby On Rails<\/a> for <a href=\"http:\/\/www.perl.com\/\">Perl<\/a>.\n<\/p>\n<p>\nNormally in Catalyst if you want to break the flow from a current method, you use the <code>forward<\/code> method of the <a href=\"http:\/\/search.cpan.org\/dist\/Catalyst\/lib\/Catalyst.pm\">catalyst object<\/a> to internally redirect to a new handler.\n<\/p>\n<p>\nImagine I have a handler responding to requests at <code>\/test<\/code>.\n<\/p>\n<p>\nIf I want my request to be dealt with by the handler at <code>\/robspage<\/code> I can issue a forward request in the handler at <code>\/test<\/code> like this&#8230;\n<\/p>\n<div class=\"code\"><code>$c->forward($c->uri_for('\/robspage'));<br \/>\n## code will continue here.<br \/>\n<\/code><\/div>\n<p>\nOnce the code at <code>\/robspage<\/code> has run, control returns to the calling handler.\n<\/p>\n<p>\nThis isn&#8217;t always what is needed, if I don&#8217;t want the handler to return and keep running I would need to use the <code>detach<\/code> method instead.\n<\/p>\n<div class=\"code\"><code>$c->detach($c->uri_for('\/robspage'));<br \/>\n## code will not continue here.<br \/>\n<\/code><\/div>\n<p>\nThis is great, however, the calling URL will not change and the user will not know they are actually seeing <code>\/robspage<\/code> instead of <code>\/test<\/code>. Sometimes this is the behaviour we want, however in this case I want the user to know a redirect has happened and for this to be reflected in their browser.\n<\/p>\n<p>\nTo achieve this, we have to use the <code>redirect<\/code> method of the the <a href=\"http:\/\/search.cpan.org\/dist\/Catalyst\/lib\/Catalyst\/Response.pm\"><code>response<\/code><\/a> object.\n<\/p>\n<div class=\"code\"><code>$c->res->redirect($c->uri_for('\/robspage'));<br \/>\n$c->detach();<br \/>\n<\/code><\/div>\n<p>\nNote that I have added a <code>$c->detach();<\/code> call after the redirect as I don&#8217;t want the processing chain to continue.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been using Catalyst quite a bit recently. For those of you who don&#8217;t know what Catalyst is, the easiest buzzword compliant comparison is Ruby On Rails for Perl. Normally in Catalyst if you want to break the flow from a current method, you use the forward method of the catalyst object to internally redirect &hellip; <a href=\"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Redirects In Catalyst&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[47],"class_list":["post-120","post","type-post","status-publish","format-standard","hentry","category-dev","tag-perl"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Redirects In Catalyst - Robert Price<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Redirects In Catalyst - Robert Price\" \/>\n<meta property=\"og:description\" content=\"I&#8217;ve been using Catalyst quite a bit recently. For those of you who don&#8217;t know what Catalyst is, the easiest buzzword compliant comparison is Ruby On Rails for Perl. Normally in Catalyst if you want to break the flow from a current method, you use the forward method of the catalyst object to internally redirect &hellip; Continue reading &quot;Redirects In Catalyst&quot;\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2009-03-06T10:04:21+00:00\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"http:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"Redirects In Catalyst\",\"datePublished\":\"2009-03-06T10:04:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/\"},\"wordCount\":221,\"keywords\":[\"Perl\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/\",\"url\":\"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/\",\"name\":\"Redirects In Catalyst - Robert Price\",\"isPartOf\":{\"@id\":\"http:\/\/www.robertprice.co.uk\/robblog\/#website\"},\"datePublished\":\"2009-03-06T10:04:21+00:00\",\"author\":{\"@id\":\"http:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"breadcrumb\":{\"@id\":\"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/www.robertprice.co.uk\/robblog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Redirects In Catalyst\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.robertprice.co.uk\/robblog\/#website\",\"url\":\"http:\/\/www.robertprice.co.uk\/robblog\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"http:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Redirects In Catalyst - Robert Price","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/","og_locale":"en_GB","og_type":"article","og_title":"Redirects In Catalyst - Robert Price","og_description":"I&#8217;ve been using Catalyst quite a bit recently. For those of you who don&#8217;t know what Catalyst is, the easiest buzzword compliant comparison is Ruby On Rails for Perl. Normally in Catalyst if you want to break the flow from a current method, you use the forward method of the catalyst object to internally redirect &hellip; Continue reading \"Redirects In Catalyst\"","og_url":"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/","og_site_name":"Robert Price","article_published_time":"2009-03-06T10:04:21+00:00","author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/#article","isPartOf":{"@id":"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/"},"author":{"name":"rob","@id":"http:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"Redirects In Catalyst","datePublished":"2009-03-06T10:04:21+00:00","mainEntityOfPage":{"@id":"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/"},"wordCount":221,"keywords":["Perl"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/","url":"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/","name":"Redirects In Catalyst - Robert Price","isPartOf":{"@id":"http:\/\/www.robertprice.co.uk\/robblog\/#website"},"datePublished":"2009-03-06T10:04:21+00:00","author":{"@id":"http:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"breadcrumb":{"@id":"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.robertprice.co.uk\/robblog\/redirects_in_catalyst-shtml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"Redirects In Catalyst"}]},{"@type":"WebSite","@id":"http:\/\/www.robertprice.co.uk\/robblog\/#website","url":"http:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"http:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"http:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"http:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=120"}],"version-history":[{"count":0,"href":"http:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/120\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}