Skip to content

Instantly share code, notes, and snippets.

@typester
Created June 30, 2009 07:15
Show Gist options
  • Save typester/138045 to your computer and use it in GitHub Desktop.
Save typester/138045 to your computer and use it in GitHub Desktop.
From bf13f9edbe14e68f7b8037ee8c0156a9e1afdbb5 Mon Sep 17 00:00:00 2001
From: Daisuke Murase <typester@cpan.org>
Date: Tue, 30 Jun 2009 16:14:13 +0900
Subject: [PATCH] fixed duplicate around attribute
---
lib/Ark/Plugin/Session/State/URI.pm | 15 +++++++--------
lib/Ark/Plugin/Session/State/URI/ExtendContext.pm | 15 +++++++++++++++
2 files changed, 22 insertions(+), 8 deletions(-)
create mode 100644 lib/Ark/Plugin/Session/State/URI/ExtendContext.pm
diff --git a/lib/Ark/Plugin/Session/State/URI.pm b/lib/Ark/Plugin/Session/State/URI.pm
index c395195..e9d27c7 100644
--- a/lib/Ark/Plugin/Session/State/URI.pm
+++ b/lib/Ark/Plugin/Session/State/URI.pm
@@ -99,14 +99,13 @@ has 'overload_uri_for' => (
sub BUILD {
my ($self) = @_;
- my $ctx = $self->app->context_class;
-
- $ctx->meta->add_around_method_modifier('uri_for', sub {
- my $next = shift;
- return $self->overload_uri_for
- ? $self->uri_with_sessionid($next->(@_))
- : $next->(@_);
- });
+ my $ctx = $self->app->context_class;
+ my $role = 'Ark::Plugin::Session::State::URI::ExtendContext';
+
+ return if $ctx->meta->does_role($role);
+
+ $self->ensure_class_loaded($role);
+ $role->meta->apply( $ctx->meta );
}
sub get_session_id_from_param {
diff --git a/lib/Ark/Plugin/Session/State/URI/ExtendContext.pm b/lib/Ark/Plugin/Session/State/URI/ExtendContext.pm
new file mode 100644
index 0000000..47925f8
--- /dev/null
+++ b/lib/Ark/Plugin/Session/State/URI/ExtendContext.pm
@@ -0,0 +1,15 @@
+package Ark::Plugin::Session::State::URI::ExtendContext;
+use Ark::Plugin;
+
+around uri_for => sub {
+ my $next = shift;
+ my ($context) = @_;
+
+ my $session = $context->session;
+
+ return $session->overload_uri_for
+ ? $session->uri_with_sessionid($next->(@_))
+ : $next->(@_);
+};
+
+1;
--
1.6.0.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment