{"action":"created","issue":{"url":"https://api.github.com/repos/PerlDancer/Dancer2/issues/972","labels_url":"https://api.github.com/repos/PerlDancer/Dancer2/issues/972/labels{/name}","comments_url":"https://api.github.com/repos/PerlDancer/Dancer2/issues/972/comments","events_url":"https://api.github.com/repos/PerlDancer/Dancer2/issues/972/events","html_url":"https://github.com/PerlDancer/Dancer2/pull/972","id":99202726,"number":972,"title":"Streamline the (to|from)_(json|yaml|dumper) serialization helpers.","user":{"login":"veryrusty","id":117258,"avatar_url":"https://avatars.githubusercontent.com/u/117258?v=3","gravatar_id":"","url":"https://api.github.com/users/veryrusty","html_url":"https://github.com/veryrusty","followers_url":"https://api.github.com/users/veryrusty/followers","following_url":"https://api.github.com/users/veryrusty/following{/other_user}","gists_url":"https://api.github.com/users/veryrusty/gists{/gist_id}","starred_url":"https://api.github.com/users/veryrusty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/veryrusty/subscriptions","organizations_url":"https://api.github.com/users/veryrusty/orgs","repos_url":"https://api.github.com/users/veryrusty/repos","events_url":"https://api.github.com/users/veryrusty/events{/privacy}","received_events_url":"https://api.github.com/users/veryrusty/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-05T13:16:43Z","updated_at":"2015-08-23T10:30:35Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/PerlDancer/Dancer2/pulls/972","html_url":"https://github.com/PerlDancer/Dancer2/pull/972","diff_url":"https://github.com/PerlDancer/Dancer2/pull/972.diff","patch_url":"https://github.com/PerlDancer/Dancer2/pull/972.patch"},"body":"The (to|from)_(json|yaml|dumper) helpers all create a new serializer\r\nobject and call (de)serialize on it. If you trace the actual calls, this\r\nis roughly (pseudo code for serialize):\r\n\r\n```\r\n  Serializer->new->serialize(@_);\r\n  # around modifier\r\n  $self->execute_hook;\r\n  original $self->serialize(...)\r\n  $self->config;  (JSON only)\r\n  do the serialization\r\n  $self->log_cb if serialization failed.\r\n```\r\n\r\nHowever, as we have a new serializer object, there are no hooks, there\r\nis no config, and the default lob_cb is `sub{1}`. ie. we make a lot of\r\nmethod calls that do nothing after the expense of generating the\r\nserializer object itself.\r\n\r\nInstead, add logical checks that ensures that those methods only\r\nget called if $self is blessed. This does not interfere with serializing\r\ncontent at the end of a route, and allows (de)serialize to be called as\r\na class method. Resolves #719 and is an alternate to #969.\r\n\r\nAnother benefit is that serialization fails when called as a class\r\nmethod will no longer be trapped and silently ignored, possibly resolving #644\r\nand alternative to #647.\r\n"},"comment":{"url":"https://api.github.com/repos/PerlDancer/Dancer2/issues/comments/133813643","html_url":"https://github.com/PerlDancer/Dancer2/pull/972#issuecomment-133813643","issue_url":"https://api.github.com/repos/PerlDancer/Dancer2/issues/972","id":133813643,"user":{"login":"veryrusty","id":117258,"avatar_url":"https://avatars.githubusercontent.com/u/117258?v=3","gravatar_id":"","url":"https://api.github.com/users/veryrusty","html_url":"https://github.com/veryrusty","followers_url":"https://api.github.com/users/veryrusty/followers","following_url":"https://api.github.com/users/veryrusty/following{/other_user}","gists_url":"https://api.github.com/users/veryrusty/gists{/gist_id}","starred_url":"https://api.github.com/users/veryrusty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/veryrusty/subscriptions","organizations_url":"https://api.github.com/users/veryrusty/orgs","repos_url":"https://api.github.com/users/veryrusty/repos","events_url":"https://api.github.com/users/veryrusty/events{/privacy}","received_events_url":"https://api.github.com/users/veryrusty/received_events","type":"User","site_admin":false},"created_at":"2015-08-23T10:30:35Z","updated_at":"2015-08-23T10:30:35Z","body":"The only place I used `__PACKAGE__` was in the methods that are called from the DSL serializaiton keywords. If you were to use a subclass of one of the core serializers, the methods the DSL calls shouldn't change. I'm not sure why one would subclass one of the core serializers; implementing a new serializer is straight forward. \r\n\r\nI'm for merging ;) "}}