ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/TemplateInterface.pm
(Generate patch)

Comparing COMP/SCRAM/src/BuildSystem/TemplateInterface.pm (file contents):
Revision 1.1 by sashby, Tue Jul 20 12:01:46 2004 UTC vs.
Revision 1.2 by sashby, Fri Dec 10 13:41:37 2004 UTC

# Line 0 | Line 1
1 + #____________________________________________________________________
2 + # File: TemplateInterface.pm
3 + #____________________________________________________________________
4 + #  
5 + # Author: Shaun Ashby <Shaun.Ashby@cern.ch>
6 + # Update: 2004-07-01 14:03:46+0200
7 + # Revision: $Id$
8 + #
9 + # Copyright: 2004 (C) Shaun Ashby
10 + #
11 + #--------------------------------------------------------------------
12 + package BuildSystem::TemplateInterface;
13 + require 5.004;
14 + use Exporter;
15 + @ISA=qw(Exporter);
16 + @EXPORT_OK=qw( );
17 +
18 + sub new()
19 +   ###############################################################
20 +   # new                                                         #
21 +   ###############################################################
22 +   # modified : Thu Jul  1 14:04:01 2004 / SFA                   #
23 +   # params   :                                                  #
24 +   #          :                                                  #
25 +   # function :                                                  #
26 +   #          :                                                  #
27 +   ###############################################################
28 +   {
29 +   my $proto=shift;
30 +   my $class=ref($proto) || $proto;
31 +   my $self={};
32 +  
33 +   bless $self,$class;
34 +
35 +   # Process the environment hash and extract a
36 +   # list of vars that are needed for building.
37 +   # NB: This is done once only!
38 +   my %exportenv;
39 +   map
40 +      {
41 +      if ($_ =~ /^SCRAM/ || $_ =~ /(LOCAL|RELEASE)TOP$/)
42 +         {
43 +         $exportenv{$_} = $ENV{$_} if ($_ !~ /^SCRAMRT\_.*$/);
44 +         }
45 +      } keys %ENV;
46 +  
47 +   # Add the environment information to the TEMPLATE_DATA hash:
48 +   $self->{TEMPLATE_DATA} = { 'environment' => \%exportenv };
49 +
50 +   # The filehandle for the generated Makefile:
51 +   my $makefile="$ENV{LOCALTOP}/$ENV{SCRAM_INTwork}/Makefile";
52 +
53 +   use FileHandle;
54 +   $self->{MAKEFILEFH} = FileHandle->new();
55 +   $self->{MAKEFILEFH}->open("> $makefile");
56 +
57 +   # Init and pass in the template location:
58 +   $self->_init(@_);
59 +   return $self;
60 +   }
61 +
62 + sub _init()
63 +   {
64 +   my $self=shift;
65 +   my ($templatedir)=@_;
66 +  
67 +   # Set the location where the templates may be found:
68 +   $self->template_dir($templatedir);
69 +   # Configure the template object:
70 +   $self->template_config();
71 +   # Create the new Template object:
72 +   $self->template_object();
73 +   return $self;
74 +   }
75 +
76 + sub template_object()
77 +   {
78 +   my $self=shift;
79 +
80 +   # Instantiate a new Template object:
81 +   eval("use Template");
82 +
83 +   if ($@)
84 +      {
85 +      print "\nSCRAM Error: It appears that the module \"Template.pm\" is not installed.","\n";
86 +      print "             Please check your installaion. If you are an administrator,","\n";
87 +      print "             you can find the Perl Template Toolkit at www.cpan.org or at","\n";
88 +      print "             the web site of the author (Andy Wardley):","\n";
89 +      print "\n";
90 +      print "             www.template-toolkit.com","\n";
91 +      print "\n";
92 +      print "             You should install version 2.xx (2.13 or better).","\n";
93 +      print "\nscram-developers\@cern.ch","\n\n";
94 +      exit(1);
95 +      }
96 +   else
97 +      {
98 +      $self->{TEMPLATE_OBJECT} = Template->new($self->{TEMPLATE_CONFIG});
99 +      }
100 +
101 +   return $self;
102 +   }
103 +
104 + sub template_dir()
105 +   {
106 +   my $self=shift;
107 +   my ($templatedir)=@_;
108 +   $templatedir ||= $ENV{LOCALTOP}."/".$ENV{SCRAM_CONFIGDIR};
109 +   $self->{TEMPLATE_DIR} = $templatedir;
110 +   return $self;
111 +   }
112 +
113 + sub template_config()
114 +   {
115 +   my $self=shift;
116 +  
117 +   # Set up Template opts:
118 +   $self->{TEMPLATE_CONFIG} =
119 +      {
120 +      INCLUDE_PATH => $self->{TEMPLATE_DIR},
121 +      PLUGIN_BASE  =>  [ qw(SCRAM::Plugins BuildSystem::Template::Plugins) ],
122 +      EVAL_PERL    => 1
123 +         };
124 +  
125 +   return $self;
126 +   }
127 +
128 + sub template_data()
129 +   {
130 +   my $self=shift;
131 +   my ($data) = @_;
132 +
133 +   # Set the things that we must set. The "data" key points
134 +   # to a DataCollector object. The "branch" data is a
135 +   # TreeItem object:
136 +   $self->{TEMPLATE} = $data->template();
137 +   # Add required data accessed by key:
138 +   $self->{TEMPLATE_DATA}->{branch} = $data;
139 +   }
140 +
141 + sub run()
142 +   {
143 +   my $self=shift;
144 +   local *FH = $self->{MAKEFILEFH};
145 +  
146 +   $self->{TEMPLATE_OBJECT}->process($self->{TEMPLATE},
147 +                                     $self->{TEMPLATE_DATA},
148 +                                     $self->{MAKEFILEFH} )
149 +      || die "SCRAM: Template error --> ",$self->{TEMPLATE_OBJECT}->error;
150 +   }
151 +
152 + 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines