1

I am reading the CIF (Collective Intelligence Framework) source code on GitHub

In the file src/lib/CIF/Generated.pm.in I saw a statement like this

use constant PROTOCOL_VERSION   => @CIF_PROTOCOL_VERSION@;

Why are there two at signs @?

package CIF;

use warnings;
use strict;

use constant VERSION =>    '@CIF_VERSION_MAJOR@.@CIF_VERSION_MINOR@.@CIF_VERSION_PATCH@@CIF_VERSION_META@';
our ($MAJOR_VERSION, $MINOR_VERSION, $PATCH, $META) = VERSION =~ /^(\d+)\.(\d+)\.(\d+)-?([\w\.\d]+)?$/;

use constant PROTOCOL_VERSION   => @CIF_PROTOCOL_VERSION@;
use constant ORG                => '@ORG@';
use constant DEFAULT_PORT       => @DEFAULT_PORT@;

use constant DEFAULT_FRONTEND_PORT          => DEFAULT_PORT();
use constant DEFAULT_BACKEND_PORT           => (DEFAULT_PORT() + 1);
use constant DEFAULT_PUBLISHER_PORT         => (DEFAULT_PORT() + 2);
use constant DEFAULT_STATS_PUBLISHER_PORT   => (DEFAULT_PORT() + 3);

our $CIF_USER = '@CIF_USER@';
our $CIF_GROUP = '@CIF_GROUP@';

our $BasePath = '@CIF_PATH@';

our $LibPath    = '@siteperldir@';
our $EtcPath    = '@ext_sysconfdir@';
our $VarPath    = '@ext_localstatedir@';

our $LogPath    = $VarPath.'/log';
our $PidPath    = $VarPath.'/run';

our $BinPath    = $BasePath . '/bin';
our $SbinPath   = $BasePath . '/sbin';


our $SmrtRulesPath      = $EtcPath . '/rules';
our $SmrtRulesDefault   = $SmrtRulesPath . '/default';
our $SmrtRulesLocal     = $SmrtRulesPath . '/local';

1;
cjm
  • 61,471
  • 9
  • 126
  • 175
duye
  • 155
  • 1
  • 3
  • 9
  • source: https://github.com/csirtgadgets/massive-octo-spice/blob/f01b0c676f653b30713dc0618324a69dd360c081/src/lib/CIF/Generated.pm.in – Hunter McMillen Dec 03 '15 at 15:28
  • @MSU_Bulldog: Just because you have reached the experience threshhold that allows you to edit questions doesn't mean you *should*. Your changes are dreadful: please retract them as they are obstructing better edits – Borodin Dec 03 '15 at 15:58

2 Answers2

9

.pm.in is not a normal extension for Perl code. Rather, .in normally indicates a template of some kind that's used to generate a file with the same name but with .in removed.

In this case, the templating system is Autoconf. If you look in configure.ac, you'll see

AC_CONFIG_FILES([
    Makefile
    src/Makefile.PL
    src/lib/CIF/Generated.pm
    elasticsearch/Makefile
    hacking/packaging/ubuntu/default/cif
])

This means that src/lib/CIF/Generated.pm will be generated from src/lib/CIF/Generated.pm.in when configure runs. The @...@ symbols (which Autoconf calls "output variables") are replaced by the configured options at that time. They aren't Perl syntax, they're Autoconf's template syntax.

In other words, Generated.pm.in is not Perl code; it's a template from which Autoconf can generate Perl code. A line like

use constant PROTOCOL_VERSION   => @CIF_PROTOCOL_VERSION@;

would become

use constant PROTOCOL_VERSION   => 1;

in src/lib/CIF/Generated.pm if configure determines that CIF_PROTOCOL_VERSION should be 1. How configure decides that is too complex to explain here; read the Autoconf manual for details.

cjm
  • 61,471
  • 9
  • 126
  • 175
2

Those do not have a meaning Perl. Strings with single quotes ' do not have variable interpolation, so those are literal @ characters, not @CIF_USER or similar arrays.

The line you mentioned actually has a syntax error in Perl.

use constant DEFAULT_PORT       => @DEFAULT_PORT@;

However, the fact that some of those are in quotes and others are not lead me to believe that these are actually template code, and that this file will be processed by some sort of templating engine before being run by Perl. In that case, @DEFAULT_PORT@ would always be a number, so it does not need quotes. At the same time, '@CIF_USER@' might result in a user name, which would probably contain things that are not numbers, so they need to be quoted.

Update: This answer to a related question explains that .in files are usually used as input for autoconf.

Community
  • 1
  • 1
simbabque
  • 53,749
  • 8
  • 73
  • 136