Global symbol requires explicit package name in pm but not in pl?

English! place to talk about development, programming and coding
Post Reply
Niroc
Znuny newbie
Posts: 18
Joined: 18 Jun 2015, 10:57
Znuny Version: 5.0.12

Global symbol requires explicit package name in pm but not in pl?

Post by Niroc »

Hi,

I'm working on some code to do a httprequest inside of a module. While it is working when I'm using it locally, it gives me errors inside of the opm.
That's my module code. The part from my $body until the my $response and say Connection error is working, when I'm using it locally inside of a .pl file. The $body variable is filled with hardcoded values in this case.

Code: Select all

# --
# Kernel/Output/HTML/FilterElementPost/TFSConnector.pm
# Copyright (C) 2015 - 2016 Perl-Services.de, http://www.perl-services.de/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

package Kernel::Output::HTML::FilterElementPost::TFSConnector;

use strict;
use warnings;
use URI::Escape;
use Cpanel::JSON::XS qw(encode_json decode_json);
use feature 'say';
use LWP::UserAgent;

our @ObjectDependencies = qw(
    Kernel::Config
    Kernel::System::Web::Request
    Kernel::Output::HTML::Layout
    Kernel::System::Ticket
    Kernel::System::Group
    Kernel::System::User
    Kernel::System::Queue
);

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = { %Param };
    bless( $Self, $Type );

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;

    my $ParamObject  = $Kernel::OM->Get('Kernel::System::Web::Request');
    my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
    my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
    my $QueueObject  = $Kernel::OM->Get('Kernel::System::Queue');
    my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
    my $GroupObject  = $Kernel::OM->Get('Kernel::System::Group');
    my $UserObject   = $Kernel::OM->Get('Kernel::System::User');

    # get template name
    my $Templatename = $Param{TemplateFile} || '';
    return 1 if !$Templatename;

    if ( $Templatename  =~ m{AgentTicketZoom\z} ) {
        my ($TicketID) = $ParamObject->GetParam( Param => 'TicketID' );

        my %Ticket = $TicketObject->TicketGet(
            TicketID => $TicketID,
            UserID   => $Self->{UserID},  
		);

		my %ArticleID = $TicketObject->ArticleFirstArticle (
			TicketID => $TicketID,
		);
		
		my %ArticleData = $TicketObject->ArticleGet(
			ArticleID => $ArticleID{'ArticleID'},
			UserID => $Self->{UserID},
		);

		my $Host = $ConfigObject->Get('TFSConnector::URL');
        
        my $body = {
            ticketid => $Ticket('TicketID'),
            tickettitle => $Ticket('Title'),
            tickettype => $Ticket('Type'),
            owner => $Ticket('Owner'),
            ownerID => $Ticket('OwnerID')
            article => $ArticleData('Body')
        };
        
        my $ua = LWP::UserAgent->new;
        my $server = "http://localhost:25344/api/tfsdata";
        my $req = HTTP::Request->new(POST => $server);
        $req->header('content-type' => 'application/x-www-form-urlencoded');

        
        my $body_json = encode_json $body;
        $body_json = "=".$body_json;
        say $body_json;
        $req->content($body_json);

        my $response = $ua->request($req);
        if ($response->is_success) {
            my $message = $response->decoded_content;
            say $message;    
        } else {
            say "Connection Error";
        }

		my $URL = $Host."?ticketid=".$TicketID."&owner=".$Ticket{'Owner'}."&article=".uri_escape($ArticleData{'Body'});
 
        my $Snippet = $LayoutObject->Output(
            TemplateFile => 'TFSConnector',
            Data         => {
				URL => $URL,		
            },
        ); 

        #scan html output and generate new html input
        ${ $Param{Data} } =~ s{(<label>Alter.*?</label>)}{$Snippet $1}mgs;
    }

    return ${ $Param{Data} };
}

1;
And this is the error.log from apache
ERROR: OTRS-CGI-44 Perl: 5.18.2 OS: linux Time: Wed Jun 8 12:07:30 2016

Message: Global symbol "$Ticket" requires explicit package name at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 74.
syntax error at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 74, near "$Ticket("
Global symbol "$Ticket" requires explicit package name at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 75.
Global symbol "$Ticket" requires explicit package name at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 76.
Global symbol "$Ticket" requires explicit package name at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 77.
Global symbol "$Ticket" requires explicit package name at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 78.
Global symbol "$ArticleData" requires explicit package name at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 79.
Global symbol "$body" requires explicit package name at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 88.
Global symbol "$Host" requires explicit package name at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 101.
Global symbol "$TicketID" requires explicit package name at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 101.
Global symbol "%Ticket" requires explicit package name at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 101.
Global symbol "%ArticleData" requires explicit package name at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 101.
Global symbol "%Param" requires explicit package name at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 114.
syntax error at /opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm line 115, near "}"
/opt/otrs/Custom/Kernel/Output/HTML/FilterElementPost/TFSConnector.pm has too many errors.


RemoteAddress: 192.168.203.220
RequestURI: /otrs/index.pl?Action=AgentTicketZoom;TicketID=62

Traceback (1423):
Module: Kernel::Output::HTML::Layout::Template::Output Line: 268
Module: Kernel::Modules::AgentTicketZoom::MaskAgentZoom Line: 1812
Module: Kernel::Modules::AgentTicketZoom::Run Line: 632
Module: Kernel::System::Web::InterfaceAgent::Run Line: 1042
Module: ModPerl::ROOT::ModPerl::Registry::opt_otrs_bin_cgi_2dbin_index_2epl::handler Line: 40
Module: (eval) (v1.99) Line: 206
Module: ModPerl::RegistryCooker::run (v1.99) Line: 206
Module: ModPerl::RegistryCooker::default_handler (v1.99) Line: 172
Module: ModPerl::Registry::handler (v1.99) Line: 31
Any ideas? I'm a little bit new in perl
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Global symbol requires explicit package name in pm but not in pl?

Post by reneeb »

Code: Select all

            ticketid => $Ticket('TicketID'),
            tickettitle => $Ticket('Title'),
            tickettype => $Ticket('Type'),
            owner => $Ticket('Owner'),
            ownerID => $Ticket('OwnerID')
            article => $ArticleData('Body')
Use curly braces instead of parenthesis...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Post Reply