File Coverage

blib/lib/Alien/Prototype/Window.pm
Criterion Covered Total %
statement 57 58 98.2
branch 6 8 75.0
condition n/a
subroutine 14 15 93.3
pod 5 5 100.0
total 82 86 95.3


line stmt bran cond sub pod time code
1             package Alien::Prototype::Window;
2              
3             ###############################################################################
4             # Required inclusions.
5             ###############################################################################
6 2     2   146369 use strict;
  2         16  
  2         56  
7 2     2   10 use warnings;
  2         4  
  2         70  
8 2     2   11 use Carp;
  2         3  
  2         98  
9 2     2   10 use File::Spec;
  2         5  
  2         53  
10 2     2   1056 use File::Copy qw(copy);
  2         8772  
  2         139  
11 2     2   14 use File::Path qw(mkpath);
  2         4  
  2         104  
12 2     2   11 use File::Find qw(find);
  2         4  
  2         195  
13 2     2   14 use File::Basename qw(dirname);
  2         4  
  2         156  
14 2     2   1048 use Alien::scriptaculous;
  2         3466  
  2         939  
15              
16             ###############################################################################
17             # Version number
18             ###############################################################################
19             our $PWC_VERSION = '1.3';
20             our $VERSION = '1.3.4';
21              
22             ###############################################################################
23             # Subroutine: version()
24             ###############################################################################
25             # Return the Prototype Window Class version number.
26             #
27             # Not to be confused with the 'Alien::Prototype::Window' version number (which
28             # is the version number of the Perl wrapper).
29             ###############################################################################
30             sub version {
31 0     0 1 0 return $PWC_VERSION;
32             }
33              
34             ###############################################################################
35             # Subroutine: path()
36             ###############################################################################
37             # Returns the path to the available copy of Prototype Window Class.
38             ###############################################################################
39             sub path {
40 3     3 1 11 my $base = $INC{'Alien/Prototype/Window.pm'};
41 3         21 $base =~ s{\.pm$}{};
42 3         11 return $base;
43             }
44              
45             ###############################################################################
46             # Subroutine: to_blib()
47             ###############################################################################
48             # Returns a hash containing paths to the soure files to be copied, and their
49             # relative destinations.
50             ###############################################################################
51             sub to_blib {
52 3     3 1 12 my $class = shift;
53 3         15 my $path = $class->path();
54 3         22 my %blib;
55              
56             # JS files
57 3         16 my @js = qw( window window_ext window_effects tooltip debug extended_debug );
58 3         10 foreach my $file (@js) {
59 18         35 $file .= '.js';
60 18         126 my $src = File::Spec->catfile( $path, 'javascripts', $file );
61 18         67 $blib{$src} = $file;
62             }
63              
64             # themes
65 3         16 my $themedir = File::Spec->catdir( $path, 'themes' );
66             File::Find::find (
67             sub {
68 528 100   528   9867 -f $_ && do {
69 495         1505 my $dstdir = $File::Find::dir;
70 495         2627 $dstdir =~ s{^$themedir/?}{};
71 495         7460 $blib{$File::Find::name} = File::Spec->catfile('window', $dstdir, $_);
72             }
73             },
74 3         362 $themedir
75             );
76              
77             # return list of files to install
78 3         368 return %blib;
79             }
80              
81             ###############################################################################
82             # Subroutine: files()
83             ###############################################################################
84             # Returns the lsit of files that are installed by Alien::Prototype::Window.
85             ###############################################################################
86             sub files {
87 1     1 1 100 my $class = shift;
88 1         5 my %blib = $class->to_blib();
89 1         125 return sort values %blib;
90             }
91              
92             ###############################################################################
93             # Subroutine: install($destdir)
94             # Parameters: $destdir - Destination directory
95             ###############################################################################
96             # Installs the Prototype Window Class into the given '$destdir'. Throws a
97             # fatal exception on errors.
98             ###############################################################################
99             sub install {
100 2     2 1 53158 my ($class, $destdir) = @_;
101              
102             # install script.aculo.us
103 2         30 Alien::scriptaculous->install( $destdir );
104              
105             # install our files
106 2         7570 my %blib = $class->to_blib();
107 2         38 while (my ($srcfile, $dest) = each %blib) {
108             # get full path to destination file
109 342         112483 my $destfile = File::Spec->catfile( $destdir, $dest );
110             # create any required install directories
111 342         10389 my $instdir = dirname( $destfile );
112 342 100       6719 if (!-d $instdir) {
113 10 50       1261 mkpath( $instdir ) || croak "can't create '$instdir'; $!";
114             }
115             # install the file
116 342 50       1676 copy( $srcfile, $destfile ) || croak "can't copy '$srcfile' to '$instdir'; $!";
117             }
118             }
119              
120             1;
121              
122             =head1 NAME
123              
124             Alien::Prototype::Window - (DEPRECATED) installing and finding Prototype Window Class
125              
126             =head1 SYNOPSIS
127              
128             use Alien::Prototype::Window;
129             ...
130             $version = Alien::Prototype::Window->version();
131             $path = Alien::Prototype::Window->path();
132             ...
133             Alien::Prototype::Window->install( $my_destination_directory );
134              
135             =head1 DESCRIPTION
136              
137             B - DO NOT USE
138              
139             Please see L for the manifesto of the Alien namespace.
140              
141             =head1 METHODS
142              
143             =over
144              
145             =item version()
146              
147             Return the Prototype Window Class version number.
148              
149             Not to be confused with the C version number
150             (which is the version number of the Perl wrapper).
151              
152             =item path()
153              
154             Returns the path to the available copy of Prototype Window Class.
155              
156             =item to_blib()
157              
158             Returns a hash containing paths to the soure files to be copied, and their
159             relative destinations.
160              
161             =item files()
162              
163             Returns the lsit of files that are installed by Alien::Prototype::Window.
164              
165             =item install($destdir)
166              
167             Installs the Prototype Window Class into the given C<$destdir>. Throws a
168             fatal exception on errors.
169              
170             =back
171              
172             =head1 AUTHOR
173              
174             Graham TerMarsch (cpan@howlingfrog.com)
175              
176             =head1 LICENSE
177              
178             Copyright (C) 2007, Graham TerMarsch. All rights reserved.
179              
180             This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
181              
182             =head1 SEE ALSO
183              
184             http://prototype-window.xilinus.com/,
185             L,
186             L.
187              
188             =cut