File Coverage

blib/lib/Sledge/Plugin/Notice.pm
Criterion Covered Total %
statement 17 30 56.6
branch 1 8 12.5
condition n/a
subroutine 5 8 62.5
pod n/a
total 23 46 50.0


line stmt bran cond sub pod time code
1             package Sledge::Plugin::Notice;
2              
3 1     1   37839 use strict;
  1         2  
  1         39  
4 1     1   6 use warnings;
  1         2  
  1         44  
5              
6             our $VERSION = '0.03';
7              
8 1     1   6 use Carp ();
  1         5  
  1         579  
9              
10             sub import {
11 1     1   9 my $class = shift;
12 1         3 my $caller = caller;
13 1 50       14 unless ($caller->isa('Sledge::Pages::Base')) {
14 1         249 Carp::carp('use it from Sledge::Pages.');
15 1         11 return;
16             }
17 0           my $sess_key = __PACKAGE__.'::notice';
18             $caller->register_hook(
19             AFTER_DISPATCH => sub {
20 0     0     my $self = shift;
21 0           my $notice = $self->notice;
22 0 0         $self->tmpl->param(notice => $notice) if $notice;
23             },
24             AFTER_OUTPUT => sub {
25 0     0     my $self = shift;
26 0           $self->session->remove($sess_key);
27             },
28 0           );
29 1     1   6 no strict 'refs';
  1         1  
  1         125  
30 0           *{"$caller\::notice"} = sub {
31 0     0     my $self = shift;
32 0 0         if (@_ == 0) {
    0          
33 0           return $self->session->param($sess_key);
34             } elsif (@_ == 1) {
35 0           $self->session->param($sess_key => $_[0]);
36             }
37 0           };
38             }
39              
40             1;
41             __END__