File Coverage

blib/lib/Alien/scriptaculous.pm
Criterion Covered Total %
statement 45 47 95.7
branch 2 6 33.3
condition n/a
subroutine 12 13 92.3
pod 5 5 100.0
total 64 71 90.1


line stmt bran cond sub pod time code
1             package Alien::scriptaculous;
2              
3             ###############################################################################
4             # Required inclusions.
5             ###############################################################################
6 2     2   130273 use strict;
  2         14  
  2         55  
7 2     2   10 use warnings;
  2         3  
  2         42  
8 2     2   9 use Carp;
  2         3  
  2         106  
9 2     2   12 use File::Spec;
  2         5  
  2         40  
10 2     2   1020 use File::Copy qw(copy);
  2         8351  
  2         111  
11 2     2   14 use File::Path qw(mkpath);
  2         3  
  2         86  
12 2     2   10 use File::Basename qw(dirname);
  2         3  
  2         137  
13 2     2   978 use Alien::Prototype;
  2         1187  
  2         744  
14              
15             ###############################################################################
16             # Version number
17             ###############################################################################
18             our $SCRIPTACULOUS_VERSION = '1.8.0';
19             our $VERSION = '1.8.0.3';
20              
21             ###############################################################################
22             # Subroutine: version()
23             ###############################################################################
24             # Returns the script.aculo.us version number.
25             #
26             # Not to be confused with the 'Alien::scriptaculous' version number (which is
27             # the version number of the Perl wrapper).
28             ###############################################################################
29             sub version {
30 0     0 1 0 return $SCRIPTACULOUS_VERSION;
31             }
32              
33             ###############################################################################
34             # Subroutine: path()
35             ###############################################################################
36             # Returns the path to the available copy of script.aculo.us.
37             ###############################################################################
38             sub path {
39 3     3 1 6 my $base = $INC{'Alien/scriptaculous.pm'};
40 3         18 $base =~ s{\.pm$}{};
41 3         6 return $base;
42             }
43              
44             ###############################################################################
45             # Subroutine: to_blib()
46             ###############################################################################
47             # Returns a hash containing paths to the source files to be copied, and their
48             # relative destinations.
49             ###############################################################################
50             sub to_blib {
51 3     3 1 7 my $class = shift;
52 3         7 my $path = $class->path();
53 3         7 my @files = map { "$_.js" }
  21         38  
54             qw( builder controls dragdrop effects scriptaculous slider
55             sound
56             );
57 3         5 my %blib = map { (File::Spec->catfile($path,'src',$_) => $_) } @files;
  21         138  
58 3         18 return %blib;
59             }
60              
61             ###############################################################################
62             # Subroutine: files()
63             ###############################################################################
64             # Returns the list of files that are installed by Alien::scriptaculous.
65             ###############################################################################
66             sub files {
67 1     1 1 72 my $class = shift;
68 1         4 my %blib = $class->to_blib();
69 1         7 return sort values %blib;
70             }
71              
72             ###############################################################################
73             # Subroutine: install($destdir)
74             # Parameters: $destdir - Destination directory
75             ###############################################################################
76             # Installs the script.aculo.us Javascript libraries into the given '$destdir'.
77             # Throws a fatal exception on errors.
78             ###############################################################################
79             sub install {
80 2     2 1 3043 my ($class, $destdir) = @_;
81              
82             # install Prototype
83 2         13 Alien::Prototype->install( $destdir );
84              
85             # install our files
86 2         1415 my %blib = $class->to_blib();
87 2         11 while (my ($srcfile, $dest) = each %blib) {
88             # get full path to destination file
89 14         3301 my $destfile = File::Spec->catfile( $destdir, $dest );
90             # create any required install directories
91 14         313 my $instdir = dirname( $destfile );
92 14 50       199 if (!-d $instdir) {
93 0 0       0 mkpath( $instdir ) || croak "can't create '$instdir'; $!";
94             }
95             # install the file
96 14 50       50 copy( $srcfile, $destfile ) || croak "can't copy '$srcfile' to '$instdir'; $!";
97             }
98             }
99              
100             1;
101              
102             =head1 NAME
103              
104             Alien::scriptaculous - (DEPRECATED) installing and finding script.aculo.us
105              
106             =head1 SYNOPSIS
107              
108             use Alien::scriptaculous;
109             ...
110             $version = Alien::scriptaculous->version();
111             $path = Alien::scriptaculous->path();
112             ...
113             Alien::scriptaculous->install( $my_destination_directory );
114              
115             =head1 DESCRIPTION
116              
117             B - DO NOT USE
118              
119             Please see L for the manifesto of the Alien namespace.
120              
121             =head1 METHODS
122              
123             =over
124              
125             =item version()
126              
127             Returns the script.aculo.us version number.
128              
129             Not to be confused with the C version number (which
130             is the version number of the Perl wrapper).
131              
132             =item path()
133              
134             Returns the path to the available copy of script.aculo.us.
135              
136             =item to_blib()
137              
138             Returns a hash containing paths to the source files to be copied, and their
139             relative destinations.
140              
141             =item files()
142              
143             Returns the list of files that are installed by Alien::scriptaculous.
144              
145             =item install($destdir)
146              
147             Installs the script.aculo.us Javascript libraries into the given
148             C<$destdir>. Throws a fatal exception on errors.
149              
150             =back
151              
152             =head1 AUTHOR
153              
154             Graham TerMarsch (cpan@howlingfrog.com)
155              
156             =head1 LICENSE
157              
158             Copyright (C) 2006, Graham TerMarsch. All rights reserved.
159              
160             This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
161              
162             =head1 SEE ALSO
163              
164             http://script.aculo.us/,
165             L,
166             L.
167              
168             =cut