15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#!/usr/bin/perl -w
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# Copyright (C) 2011 Apple Inc. All rights reserved.
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# Copyright (C) 2011 Google Inc. All rights reserved.
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# Redistribution and use in source and binary forms, with or without
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# modification, are permitted provided that the following conditions
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# are met:
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# 1.  Redistributions of source code must retain the above copyright
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#     notice, this list of conditions and the following disclaimer.
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# 2.  Redistributions in binary form must reproduce the above copyright
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#     notice, this list of conditions and the following disclaimer in the
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#     documentation and/or other materials provided with the distribution.
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# Imports Perl scripts into a package for easy unit testing.
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)package LoadAsModule;
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)use strict;
315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)use warnings;
325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)use File::Spec;
345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)use FindBin;
355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)use lib File::Spec->catdir($FindBin::Bin, "..", "..");
365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)use webkitdirs;
375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)use base 'Exporter';
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)use vars qw(@EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)@EXPORT = ();
425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)@EXPORT_OK = ();
435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)%EXPORT_TAGS = ();
445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)$VERSION = '1.0';
455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)sub readFile($);
475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)sub import
495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    my ($self, $package, $script) = @_;
515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    my $scriptPath = File::Spec->catfile(sourceDir(), "Tools", "Scripts", $script);
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    eval "
535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        package $package;
545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        use strict;
565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        use warnings;
575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        use base 'Exporter';
595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        use vars qw(\@EXPORT \@EXPORT_OK \%EXPORT_TAGS \$VERSION);
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        \@EXPORT = ();
625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        \@EXPORT_OK = ();
635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        \%EXPORT_TAGS = ();
645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        \$VERSION = '1.0';
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        sub {" . readFile($scriptPath) . "}
675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ";
685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)sub readFile($)
715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    my $path = shift;
735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    local $/ = undef; # Read in the whole file at once.
745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    open FILE, "<", $path or die "Cannot open $path: $!";
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    my $contents = <FILE>;
765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    close FILE;
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return $contents;
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)1;
81