File: Component.pm

package info (click to toggle)
libmason-plugin-cache-perl 0.05-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 132 kB
  • sloc: perl: 203; makefile: 7
file content (35 lines) | stat: -rw-r--r-- 966 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package Mason::Plugin::Cache::Component;
BEGIN {
  $Mason::Plugin::Cache::Component::VERSION = '0.05';
}
use Mason::PluginRole;

my %memoized;

method cache_memoized ($class:) {
    $class = ref($class) || $class;
    if (@_) { $memoized{$class} = $_[0] }
    return $memoized{$class};
}

method cache_defaults ($class:)   { $class->cmeta->interp->cache_defaults }
method cache_root_class ($class:) { $class->cmeta->interp->cache_root_class }
method cache_namespace ($class:)  { $class->cmeta->path }

method cache ($class:) {
    if ( !@_ && $class->cache_memoized ) {
        return $class->cache_memoized;
    }
    my $cache_root_class = $class->cache_root_class;
    my %options = ( %{ $class->cache_defaults }, @_ );
    if ( !exists( $options{namespace} ) ) {
        $options{namespace} = $class->cache_namespace;
    }
    my $cache = $cache_root_class->new(%options);
    if ( !@_ ) {
        $class->cache_memoized($cache);
    }
    return $cache;
}

1;