Thursday 24 October 2019

bless - place and plays in perl

WITHOUT   BLESS                                      WITH BLESS
                                                                       
                                                           package Class;
package Class;                                   sub new  { $classname = @_; 

sub new  { $classname = @_;                 $var = {};
$var= {};                                              bless($var, $classname);
return $var; }                                         return $var; }
sub sample { print("TEST"); }       sub sample{ print("TEST"); }
$var1 = Class->new();                       $var1 = Class->new(); 
$o->sample();                                        $o->sample();    
                                               
    
Output:                                                          Output:
Error                                                                TEST
            



Method 1:

sub new { 
  $classvar = shift; 
  $selfref = {};  
  bless $selfref, $classvar; 
}


Method 2:

sub new
{
$a={};
return bless $a;
}


Method 3:

sub new
{
$a={};
bless($a);
return $a;
}


Method 4:

sub new
{
$classvar = shift;
$a={};
bless($a,$classvar);
return $a;
}

Method 5:

sub new
{
$classname=shift;
$a={};
$a->{NAME}="apple";
bless $a,$classname;
}

Method 6:

sub new
{
$classname=shift;
$a=[];
$a->[0]=100;
bless $a,$classname;
return $a;
}

Method 7:

my $x = bless [], "packagename";
$x->functionname;

Method 8:

sub new {
    classvar = $_[0];
    my $var = $_[1]->{'name'};
 
    my $this = {
        'name' => $var,
    }; 
    bless($this, $classvar);
    return $this;
}

Method 9:

 $var1= "scalar";
$var2 = bless \$s, $classname;
return $var2;


Method 10:

my $obj = bless($ref, "Class");
    sub bless {
      my ($ref, $class) = @_;
      $ref->{classname} = $class;
      return $ref;
    }

Method 11:


sub new { 
  $classname = shift; 
  $self = [];  
  bless $self, $classname; 
}


Method 12:

sub new
{
$a=[];
return bless $a;
}

Thursday 25 April 2024

Perl Subroutines Handling @_ and shift without Argument Interchange


In Perl, subroutines are a fundamental component for reusing code and managing complexity. However, handling arguments within these subroutines using @_ and shift can sometimes lead to confusion and errors if not done properly. This blog post aims to clarify these concepts and provide practical examples to ensure that you handle subroutine arguments effectively and avoid common pitfalls.Read more »

Labels:

Saturday 11 March 2023

How to Build an Authentication API with JWT Token in Perl

Hi, In many web applications, user authentication is a critical feature that allows users to securely log in and access their data. One common approach to implementing authentication is to use JSON Web Tokens (JWT), which are a type of token-based authentication that can be used across multiple domains and platforms.

In this tutorial, we will show you how to build an authentication API with JWT token in Perl. We will be using the Mojolicious web framework, which is a powerful and flexible framework that makes it easy to build web applications in Perl.

Read more »

Labels: , , ,