File Coverage

blib/lib/Alien/Prototype/Carousel.pm
Criterion Covered Total %
statement 44 46 95.6
branch 2 6 33.3
condition n/a
subroutine 12 13 92.3
pod 5 5 100.0
total 63 70 90.0


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