1#!/usr/bin/perl -w 2# 3# Copyright (C) 2011 Apple Inc. All rights reserved. 4# Copyright (C) 2011 Google Inc. All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 16# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 19# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25# 26# Imports Perl scripts into a package for easy unit testing. 27 28package LoadAsModule; 29 30use strict; 31use warnings; 32 33use File::Spec; 34use FindBin; 35use lib File::Spec->catdir($FindBin::Bin, "..", ".."); 36use webkitdirs; 37 38use base 'Exporter'; 39use vars qw(@EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION); 40 41@EXPORT = (); 42@EXPORT_OK = (); 43%EXPORT_TAGS = (); 44$VERSION = '1.0'; 45 46sub readFile($); 47 48sub import 49{ 50 my ($self, $package, $script) = @_; 51 my $scriptPath = File::Spec->catfile(sourceDir(), "Tools", "Scripts", $script); 52 eval " 53 package $package; 54 55 use strict; 56 use warnings; 57 58 use base 'Exporter'; 59 use vars qw(\@EXPORT \@EXPORT_OK \%EXPORT_TAGS \$VERSION); 60 61 \@EXPORT = (); 62 \@EXPORT_OK = (); 63 \%EXPORT_TAGS = (); 64 \$VERSION = '1.0'; 65 66 sub {" . readFile($scriptPath) . "} 67 "; 68} 69 70sub readFile($) 71{ 72 my $path = shift; 73 local $/ = undef; # Read in the whole file at once. 74 open FILE, "<", $path or die "Cannot open $path: $!"; 75 my $contents = <FILE>; 76 close FILE; 77 return $contents; 78}; 79 801; 81