File Coverage

blib/lib/Template/Plugin/Tooltip.pm
Criterion Covered Total %
statement 33 33 100.0
branch 7 12 58.3
condition 1 3 33.3
subroutine 13 13 100.0
pod 1 4 25.0
total 55 65 84.6


line stmt bran cond sub pod time code
1             package Template::Plugin::Tooltip;
2              
3             =pod
4              
5             =head1 NAME
6              
7             Template::Plugin::Tooltip - Template Toolkit plugin for HTML::Tooltip::JavaScript
8              
9             =head1 SYNOPSIS
10              
11             Load the tooltip generator.
12             Params are passed straight to to HTML::Tooltip::JavaScript->new
13             [% USE Tooltip( 'javascript_dir', '../../../static/js/', 'options',
14             bordercolor => "#000000",
15             title => '',
16             ) %]
17            
18             Add a tooltip to a link
19            
20             html_tooltip_content,
21             param, value,
22             param, value,
23             %]>Link content
24              
25             =head1 DESCRIPTION
26              
27             Template::Plugin::Tooltip is a Template Toolkit hook to the marvelous
28             L module.
29              
30             The first version was written in 30 minutes following the talk on
31             HTML::Tooltip::Javascript at the Open Source Developers Conference,
32             just after its initial release.
33              
34             =head2 API Overview
35              
36             This module is very much just a thin layer over the top of the
37             HTML::Tooltip::JavaScript API, and you should probably go read and
38             understand its API before using this module.
39              
40             To summarise VERY briefly, when you load in the plugin, the params go as
41             params to the H::T::Javascript C constructor, with the new Tooltip
42             object stored internally. When you create a tooltip, the HTML content and
43             parameters are passed directly to H::T::Javascript C method.
44              
45             =head2 Loading the Tooltip Generator
46              
47             To load the tooltip generator with the default options, you can simple do
48             the following.
49              
50             [% USE Tooltip %]
51              
52             In the same way you pass params to the HTML::Tooltip::Javascript
53             constructor, you can also pass params when loading in the Tooltip plugin.
54              
55             [% USE Tooltip('param', 'value') %]
56              
57             =head2 Using the Tooltip Generator
58              
59             L provides one simple method through which
60             you generate all the different tooltips.
61              
62             In Template::Plugin::Tooltip, you just use the loaded plugin directly.
63              
64             [% Tooltip( 'This is my plain tooltip' ) %]
65              
66             This only generates the Javascript tag properties, so this needs to be used
67             within a tag, like an anchor tag.
68              
69             item
70              
71             The first param is literal HTML content, and you can provide any additional
72             parameters you want for the tooltip, as you would do create the tooltip
73             directly.
74              
75             item
76              
77             =head2 Initialising the Tooltip Library
78              
79             The one additional step you will need to do is load in the tooltip
80             JavaScript library that drives the whole thing.
81              
82             To do this, simple add the following to the end of the page, or to the
83             EheadE section of your HTML document.
84              
85             [% Tooltip() %]
86              
87             =head2 Use as a Filter
88              
89             TO BE COMPLETED
90              
91             =cut
92              
93 2     2   22466 use 5.005;
  2         8  
  2         74  
94 2     2   9 use strict;
  2         4  
  2         75  
95 2     2   22 use Scalar::Util ();
  2         3  
  2         27  
96 2     2   1910 use Template::Plugin ();
  2         11332  
  2         39  
97 2     2   2014 use HTML::Tooltip::Javascript ();
  2         1629  
  2         50  
98              
99 2     2   12 use vars qw{$VERSION @ISA};
  2         3  
  2         120  
100             BEGIN {
101 2     2   4 $VERSION = '1.08';
102 2         590 @ISA = 'Template::Plugin';
103             }
104              
105             # Inlined copy of Params::Util::_INSTANCE
106             sub _INSTANCE ($$) {
107 1 50 33 1   15 (Scalar::Util::blessed($_[0]) and $_[0]->isa($_[1])) ? $_[0] : undef;
108             }
109              
110              
111              
112              
113              
114             #####################################################################
115             # Constructor
116              
117             sub new {
118 1 50   1 1 81410 my $class = ref $_[0] ? ref shift : shift;
119 1 50       7 my $Context = _INSTANCE(shift, 'Template::Context')
120             or $class->error('Tooltip constructor called without Template::Context');
121              
122             # Create a new ::Tooltip object, passing on params
123 1 50       10 my $Tooltip = HTML::Tooltip::Javascript->new( @_ )
124             or $class->error('Bad params to Tooltip generator constructor');
125              
126             # Create our TT interface object
127 1         25 my $self = bless {
128             Tooltip => $Tooltip,
129             }, $class;
130              
131             # Wrap in the closure subroutine
132 1 100   2   5 sub { defined $_[0] ? $self->tooltip(@_) : $self->head };
  2         667  
133             }
134              
135             sub tooltip {
136 1     1 0 2 my $self = shift;
137              
138             # If we don't get any parameters, we want a direct handle to the
139             # object so that we can call init.
140 1 50       3 return $self unless @_;
141              
142             # Pass everything straight through to the HTML::Tooltip::JavaScript
143             # object we created earlier.
144 1         3 my ($html, %params) = @_;
145 1         10 $self->{Tooltip}->tooltip( $html, \%params );
146             }
147              
148             sub head {
149 1     1 0 6 $_[0]->at_end;
150             }
151              
152             sub at_end {
153 1     1 0 6 $_[0]->{Tooltip}->at_end;
154             }
155              
156             1;
157              
158             =pod
159              
160             =head1 SUPPORT
161              
162             Bugs should be submitted via the CPAN bug tracker, located at
163              
164             L
165              
166             For other issues, or commercial enhancement or support, contact the author..
167              
168             =head1 AUTHOR
169              
170             Adam Kennedy Eadamk@cpan.orgE
171              
172             =head1 ACKOWLEDGEMENTS
173              
174             Thank you to Phase N Australia for permitting the open sourcing and release
175             of this distribution as a spin-off from a commercial project.
176              
177             =head1 COPYRIGHT
178              
179             Copyright 2004 - 2008 Adam Kennedy.
180              
181             This program is free software; you can redistribute
182             it and/or modify it under the same terms as Perl itself.
183              
184             The full text of the license can be found in the
185             LICENSE file included with this module.
186              
187             =cut