catlxom メモ #3

$self->stash でセットした値を、$self->stashall で取り出すと、以下の様なハッシュリファレンスが返ってきます。

{
    'Catlxom::Plugin::Paginate::Simple' => {
        'pager' => bless( {
            'total_entries'    => 14,
            'current_page'     => 2,
            'entries_per_page' => '5'
        }, 'Data::Page' )
}

で、これをテンプレートで扱おうとして、

[% Catlxom::Plugin::Paginate::Simple.pager.current_page %]

などと記述すると、

unexpected token (Catlxom::Plugin::Paginate::Simple)

といったエラーになります。: が入ってるのがまずいのと、冗長で書くのがめんどくさいので、以下の様な patch を書いてみました。

Index: lib/Catlxom/Context/Base.pm
===================================================================
--- lib/Catlxom/Context/Base.pm (revision 23)
+++ lib/Catlxom/Context/Base.pm (working copy)
@@ -57,7 +57,8 @@

 sub stash {
     my $self   = shift;
-    my $caller = caller(0);
+    ( my $caller = lc caller(0) ) =~ s/Catlxom::Plugin:://i;
+    $caller =~ s/::/_/g;

     if (@_) {
         my $stash = @_ > 1 ? {@_} : $_[0];

これでテンプレートの中で以下の様に記述できます。

[% pagenate_simple.pager.current_page %]