[ic] User Defined Tags - problem

Ed LaFrance interchange-users@interchange.redhat.com
Tue Apr 30 11:15:34 2002


At 09:01 AM 4/30/2002 +0930, you wrote:
>Hi list;
>
>I have my own defined tag that look like this:
>
>UserTag get-license Order email CompanyName CompanyAddress URLLimit
>HostIPAddr IssueDate ExpiryDate SerialNumber MappingLimit Evaluation
>UserTag get-license-temporary AddAttr
>UserTag get-license-temporary Documentation <<EOD
>
>usage: [get-license-temporary  email  CompanyName CompanyAddress
>URLLimit HostIPAddr IssueDate ExpiryDate SerialNumber MappingLimit
>Evaluation]
>
>Gets a license number from the license server
>EOD
>
>UserTag get-license-temporary Routine <<EOR
>use Socket;
>sub {
>  my (    $email, $CompanyName, $CompanyAddress,
>   $URLLimit, $HostIPAddr,
>          $IssueDate, $ExpiryDate, $SerialNumber, $MappingLimit,
>$Evaluation,
>   $opt ) = @_;
>
>  my $licensehost = "licenseserver";
>  my $licenseport = "2201";
>
>
>if ($MappingLimit == ""){
>    my $licensestr = "\
>         CONTACT-EMAIL=$email\
>         COMPANY-NAME=$CompanyName\
>         COMPANY-ADDRESS=$CompanyAddress\
>         URL-LIMIT=$URLLimit\
>         HOST-IP-ADDRESS=$HostIPAddr\
>         ISSUE-DATE=$IssueDate\
>         EXPIRY-DATE=$ExpiryDate\
>         SERIAL-NUMBER=$SerialNumber\
>         EVALUATION=$Evaluation\
>         ";
>}
>else{
>          my $licensestr = "\
>         CONTACT-EMAIL=$email\
>         COMPANY-NAME=$CompanyName\
>         COMPANY-ADDRESS=$CompanyAddress\
>         URL-LIMIT=$URLLimit\
>         HOST-IP-ADDRESS=$HostIPAddr\
>         ISSUE-DATE=$IssueDate\
>         EXPIRY-DATE=$ExpiryDate\
>         SERIAL-NUMBER=$SerialNumber\
>         MAPPING_LIMIT=$MappingLimit\
>         EVALUATION=$Evaluation\
>         ";
>}
>   my $iaddr = inet_aton($licensehost);
>    my $paddr = sockaddr_in($licenseport,$iaddr);
>    my $proto = getprotobyname('tcp');
>
>    socket(SOCK,PF_INET,SOCK_STREAM,$proto) || return undef;
>    connect(SOCK,$paddr) || return undef;
>    print SOCK $licensestr;
>    print SOCK "\0";
>    my $fh = select SOCK;
>    $| = 1;
>    select $fh;
>
>
>    my $signed_license = '';
>    my $buf = '';
>
>    my $line;
>    while (defined($line = <SOCK>)) {
>         $signed_license .= $line;
>         }
>    close(SOCK) || return undef;
>
>    return $signed_license;
>
>}
>EOR
>
>
>I am getting following error message:
>
>UserTag 'get_license_temporary' subroutine failed compilation:
>
>   Global symbol "$licensestr" requires explicit package name at (eval
>109) line 25, <GLOBAL> line 74.
>
>In line 74 of the configuration file
>'usertag/get_license_temporary.tag':
>UserTag get-license-temporary Routine <<EOR
>
>
>I defined this tag as get_license_temporary.tag in
>/usr/lib/interchange/usertag
>
>As soon as I remove if  and else statments works perfect ie if I have
>just this:
>UserTag get-license Order email CompanyName CompanyAddress URLLimit
>HostIPAddr IssueDate ExpiryDate SerialNumber MappingLimit Evaluation
>UserTag get-license-temporary AddAttr
>UserTag get-license-temporary Documentation <<EOD
>
>usage: [get-license-temporary  email  CompanyName CompanyAddress
>URLLimit HostIPAddr IssueDate ExpiryDate SerialNumber MappingLimit
>Evaluation]
>
>Gets a license number from the license server
>EOD
>
>UserTag get-license-temporary Routine <<EOR
>use Socket;
>sub {
>  my (    $email, $CompanyName, $CompanyAddress,
>   $URLLimit, $HostIPAddr,
>          $IssueDate, $ExpiryDate, $SerialNumber, $MappingLimit,
>$Evaluation,
>   $opt ) = @_;
>
>  my $licensehost = "licenseserver";
>  my $licenseport = "2201";
>
>
>  my $licensestr = "\
>         CONTACT-EMAIL=$email\
>         COMPANY-NAME=$CompanyName\
>         COMPANY-ADDRESS=$CompanyAddress\
>         URL-LIMIT=$URLLimit\
>         HOST-IP-ADDRESS=$HostIPAddr\
>         ISSUE-DATE=$IssueDate\
>         EXPIRY-DATE=$ExpiryDate\
>         SERIAL-NUMBER=$SerialNumber\
>         EVALUATION=$Evaluation\
>         ";
>...............................(rest of the thing).
>
>I nedd to check if some of the past values are empty, in which case they
>wll not be included in license.
>
>Thank you.
>
>
>Alma

I've run into this to - I usually get the same kind of error when trying to 
declare a new var with 'my' conditionally (inside an if block). Just 
initialize $licensestr at the beginning of your code, i.e.:

my (    $email, $CompanyName, $CompanyAddress,
   $URLLimit, $HostIPAddr,
          $IssueDate, $ExpiryDate, $SerialNumber, $MappingLimit,
$Evaluation,
   $opt ) = @_;

  my $licensehost = "licenseserver";
  my $licenseport = "2201";
  my $licensestr;

No harm done, and the problem will go away. BTW, you have declared this 
Usertag as both get-license and get-license-temporary. You should probably 
go with one or the other :-)

- Ed L.


===============================================================
New Media E.M.S.               Software Solutions for Business
463 Main St., Suite D          eCommerce | Consulting | Hosting
Placerville, CA  95667         edl@newmediaems.com
(530) 622-9421                 http://www.newmediaems.com
(866) 519-4680 Toll-Free       (530) 622-9426 Fax
===============================================================