• perl 中的面向对象多继承


     perl 面向对象继承:
    [root@jxglapp1 pfwx-master]# pwd
    /root/pfwx-master
    
    
    use lib "./lib";
    use mojo::Client;
    use Data::Dumper;
    use Mojolicious::Lite;
    use JSON qw/encode_json decode_json/;  
    use Encode;
    no strict;
    no warnings;
    use JSON; 
    use POSIX;
    use JSON::RPC::Client;
    use Data::Dumper;
    use URI::Escape;
    use DBI; 
    my $dbName = 'serv';  
    my $dbUser = 'SMSsendx';  
    my $dbUserPass = 'SMSsendx';
    #my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database " ;
    my $client = mojo::Client->new();
      print Dumper($client);
      get '/api/SMSsendx' => sub {
       my $c = shift;
       #my $sourceip=$c->param('sourceip');
       my $message = $c->param('message');
          print "Length1==";
          print length($message)."
    "; 
          $sms=$message;
          ##utf-8 flag
          my $flag=Encode::is_utf8($message);
          print "$flag===$flag
    ";
          if ($flag)
              { 
             Encode::_utf8_off($message);
             print "Length2==";
             print length($message)."
    ";
             $sms=encode_utf8($sms);
             $sms=encode("gbk",decode("utf8",$sms)) }
          else
              {$message=encode("utf8",decode("gbk",$message)) };
               
          #$message=encode_utf8($message);g===$flag
    ";
          my $phone = $c->param('phone');
          my @phone= split(/|/,$phone);
          $client->SMSsendx("$sms",@phone);
          #mojo::Client::LoadDb::insertdb(1,$sourceip,$message,$phone);
          #$client->insertdb($sourceip,$message,$phone);
         $c->render(json =>{retcode,0000});
           };
    
          get '/api/SMSinfo' => sub {
          my $c=shift;
          my $sourceip=$c->param('sourceip');
          my @arr=$client->SMSinfo($sourceip);
            $c->render(json =>@arr);
           };
      app->start;
      
      ------------------------------------------------------------------------
      [root@jxglapp1 pfwx-master]# cat lib/mojo/Client.pm 
    package mojo::Client;
    use base qw(
        mojo::Client::SMSsendx
        mojo::Client::LoadDb
       
    );
    
    our $VERSION = "1.0";
    sub new{
        my $class = shift;
            my $self= {
            client_version          => $VERSION
            };
            bless $self,$class;
           return $self;
    };
    1;
    
    
    让 mojo::Client 去继承 mojo::Client::SMSsendx
    
    
    [root@jxglapp1 pfwx-master]# cat lib/mojo/Client/SMSsendx.pm
    package mojo::Client::SMSsendx;
        use IO::Socket::INET;
        use Data::Dumper;
        use Encode;
    sub SMSsendx {
       my $self=shift;
       my $message=shift;
       my $refphone=shift;
       # print "sock$message is $message
    ";
       foreach $phone (@{$refphone}){ 
        $|=1;
        $sock = IO::Socket::INET->new(PeerAddr => '10.3.229.1',
                                       PeerPort => '745',
                                       Proto=>'tcp'
                                   ) or die "$!
    ";
       my $data="";
       my $tab=chr(9);
    

  • 相关阅读:
    一对多关系处理
    java中转换不同时区的时间
    maven
    学习设计模式
    算法
    mongodb学习总结
    mybatis源码分析(四) mybatis与spring事务管理分析
    学习数据库四大特性及事务隔离级别
    mybatis源码分析(三) mybatis-spring整合源码分析
    mybatis源码分析(二) 执行流程分析
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349456.html
Copyright © 2020-2023  润新知