File Coverage

blib/lib/CatalystX/Plugin/Blurb.pm
Criterion Covered Total %
statement 12 34 35.2
branch 0 16 0.0
condition 0 11 0.0
subroutine 4 8 50.0
pod 3 3 100.0
total 19 72 26.3


line stmt bran cond sub pod time code
1             package CatalystX::Plugin::Blurb;
2 1     1   39607 use strict;
  1         3  
  1         31  
3 1     1   5 use warnings;
  1         1  
  1         345  
4              
5             our $VERSION = "0.03";
6              
7             sub blurb {
8 0     0 1   my $c = shift;
9 0   0       $c->{__blurbs} ||= $c->flash->{__blurb} || [];
      0        
10 0 0         unless ( @_ ) { return wantarray ? @{ $c->{__blurbs} } : $c->{__blurbs} };
  0 0          
  0            
11 0 0         my @added = ref($_[0]) eq "ARRAY" ? @{$_[0]} : @_;
  0            
12 0           for my $new ( @added )
13             {
14 0 0         my $raw = ref($new) eq "HASH" ? $new : { id => $new };
15 0   0       $raw->{render} ||= $c->config->{__PACKAGE__}->{render};
16 0           my $blurb = CatalystX::Plugin::Blurb::blurb->new( $raw );
17 0           push @{$c->{__blurbs}}, $blurb;
  0            
18             }
19             }
20              
21             sub finalize {
22 0     0 1   my $c = shift;
23 0 0         $c->flash( __blurb => [ $c->blurb ] ) if $c->flash_blurb;
24 0           $c->next::method(@_);
25             }
26              
27             sub flash_blurb {
28 0     0 1   my $c = shift;
29 0 0         $c->{_flash_blurb} = shift if @_;
30 0           $c->{_flash_blurb};
31             }
32              
33             {
34             package CatalystX::Plugin::Blurb::blurb;
35 1     1   907 use parent "Class::Accessor::Fast";
  1         323  
  1         5  
36 1     1   19342 use overload '""' => "render_or_default";
  1         1219  
  1         6  
37              
38             __PACKAGE__->mk_accessors( qw( id priority mime_type content
39             render ) );
40              
41             sub render_or_default {
42 0     0     my $self = shift;
43 0 0         return $self->render->($self) if $self->render;
44 0 0 0       $self->content || $self->id || $self;
45             }
46             }
47              
48             1;
49              
50             __END__
51              
52             =pod
53              
54             =head1 NAME
55              
56             CatalystX::Plugin::Blurb - (alpha software) handle transient messages and UI elements.
57              
58             =head1 VERSION
59              
60             0.03
61              
62             =head1 NOTICE
63              
64             This is not something I'd encourage you to use yet. I am releasing it to the CPAN so it can be available for building another package. This is half done. It was written well over a year ago and barely used or touched since. It might be a mistake. It might be abandoned. If you try it though, have fun.
65              
66             =head1 SYNOPSIS
67              
68             use Catalyst qw(
69             Unicode
70             Session
71             +CatalystX::Plugin::Blurb
72             );
73              
74             =head1 DESCRIPTION
75              
76             =over 4
77              
78             =item blurb
79              
80              
81             =item flash_blurb
82              
83             Blurbs are normally only kept for a single response. If you set C<flash_blurb> to true the blurbs will be kept for the next request via L<flash|Catalyst::Plugin::Session/flash>.
84              
85             =item * finalize
86              
87             Puts the blurbs into flash for the next request if C<flash_blurb> has been set.
88              
89             =back
90              
91             =head1 CONFIGURATION AND ENVIRONMENT
92              
93             =head1 BUGS AND LIMITATIONS
94              
95             No bugs have been reported.
96              
97             Please report any bugs or feature requests to C<bug-catalyst-plugin-blurb@rt.cpan.org>, or through the web interface at L<http://rt.cpan.org>.
98              
99             =head1 TODO
100              
101             Flash blurb interface is wrong. They should be just like blurbs, not a switch. They should also have an expiration baked in.
102              
103             =head1 AUTHOR
104              
105             Ashley Pond V C<< <ashley@cpan.org> >>.
106              
107             =head1 LICENCE AND COPYRIGHT
108              
109             Copyright (c) 2009, Ashley Pond V.
110              
111             This module is free software; you can redistribute it and/or
112             modify it under the same terms as Perl itself. See L<perlartistic>.
113              
114             =head1 DISCLAIMER OF WARRANTY
115              
116             Because this software is licensed free of charge, there is no warranty
117             for the software, to the extent permitted by applicable law. Except when
118             otherwise stated in writing the copyright holders and/or other parties
119             provide the software "as is" without warranty of any kind, either
120             expressed or implied, including, but not limited to, the implied
121             warranties of merchantability and fitness for a particular purpose. The
122             entire risk as to the quality and performance of the software is with
123             you. Should the software prove defective, you assume the cost of all
124             necessary servicing, repair, or correction.
125              
126             In no event unless required by applicable law or agreed to in writing
127             will any copyright holder, or any other party who may modify and/or
128             redistribute the software as permitted by the above licence, be
129             liable to you for damages, including any general, special, incidental,
130             or consequential damages arising out of the use or inability to use
131             the software (including but not limited to loss of data or data being
132             rendered inaccurate or losses sustained by you or third parties or a
133             failure of the software to operate with any other software), even if
134             such holder or other party has been advised of the possibility of
135             such damages.
136              
137             =cut
138              
139              
140             stash_it => 1, # default
141             flash_it
142              
143             ...? NO?
144              
145             EXPIRES? One view? 2 minutes? ...?
146              
147             accessor: blurb
148              
149             order_by
150             fifo
151             lifo
152             short2long
153             long2short
154             priority
155             render
156              
157             sub object:
158             mime_type
159             content
160             priority
161