Update pin_base.mpb
[MPC.git] / modules / CommandHelper.pm
blob2437edfcea8fa8941a288e5b00763091308a8ad7
1 package CommandHelper;
3 # ************************************************************
4 # Description : Base class and factory for all command helpers.
6 # The get() method converts the define custom type
7 # provided to uppercase, removes the '_FILES' portion and
8 # adds 'Helper' to the end. If a module is found matching
9 # that name, it will be used to assist the ProjectCreator
10 # in determining which output files will be generated by
11 # the command given the file name and command options.
13 # Author : Chad Elliott
14 # Create Date : 6/30/2008
15 # ************************************************************
17 # ************************************************************
18 # Pragmas
19 # ************************************************************
21 use strict;
22 use File::Basename;
24 # ************************************************************
25 # Data Section
26 # ************************************************************
28 my %required;
29 my %notfound;
31 # ************************************************************
32 # Subroutine Section
33 # ************************************************************
35 sub get {
36 ## Create the helper name
37 my $type = uc(shift);
38 $type =~ s/_FILES$/Helper/;
40 ## Don't search the filesystem again if we didn't find one the first
41 ## time we looked.
42 return undef if ($notfound{$type});
44 ## Return the helper if we've already created one
45 return $required{$type} if (defined $required{$type});
47 ## Assist users in figuring out why their helper isn't being picked up.
48 OutputMessage::debug(undef, "Searching @INC for $type.pm");
50 ## If we can find a helper with this name, we will
51 ## create a singleton of that type and return it.
52 foreach my $inc (@INC) {
53 if (-r "$inc/$type.pm") {
54 require "$type.pm";
55 $required{$type} = $type->new();
56 return $required{$type};
60 ## We didn't find a helper. Keep track of that fact and return undef.
61 $notfound{$type} = 1;
62 return undef;
65 sub new {
66 my $class = shift;
67 return bless {}, $class;
70 sub get_output {
71 ## This method is called with the filename and command options and
72 ## returns an array reference containing filenames that will be
73 ## generated but can not be described using the normal Define_Custom
74 ## syntax. An optional second return value is a hash reference
75 ## describing additional dependencies as {type => {file => [deps]}}.
76 ## It's used to tell MPC that 'file' (one of the outputs) belongs to
77 ## 'type' and has additional dependencies 'deps'.
78 return [];
81 sub get_outputexts {
82 ## This method is expected to return an array reference containing the
83 ## extensions for files returned by the get_output() method. They will
84 ## be used as regular expressions so regular expression characters
85 ## (such as '.', '[', ']', etc.) must be escaped. This can be done by
86 ## calling $self->Parser::escape_regex_special($str);
87 return [];
90 sub get_tied {
91 ## This method is called with a file name and an array reference of
92 ## files. The first expected return value is an array reference of those
93 ## files listed in the passed array reference that are in some way tied
94 ## to the file name passed in. The second is a component name to help
95 ## MPC figure out a way to tie the files together. The result of "tied"
96 ## files is that they may be compiled after the file name passed in.
97 return [], undef;
100 sub set_creator {
101 my($self, $creator) = @_;
102 $self->{'creator'} = $creator;