SlideShare a Scribd company logo
1 of 131
Download to read offline
Perl Sucks!
(and what to do about it)
What this talk is not
ā€¢ ā€œWah, no one uses ā€˜use strictā€™ā€
ā€¢ ā€œPeopleā€™s perception of Perl is wrongā€
ā€¢ ā€œThe CPAN/mailing list/a other website
  isnā€™t exactly how I like itā€
ā€¢ ā€œThe garbage collection de-allocation
  routine isnā€™t very efļ¬centā€
What this talk is


ā€¢ Whatā€™s a few major annoyances with Perl
ā€¢ What we the humble programmer can do to
  work around them
~/bin
scp ~/bin nethost:
ssh newhost
jabme -m ā€˜compile doneā€™
Module ā€œJabber::Liteā€
    not found
-bash: jabme: /usr/local/bin/
 perl: bad interpreter: No
   such ļ¬le or directory
My Scripts Need


ā€¢ A particular version of Perl
ā€¢ A set of Perl modules
PAR
#!/usr/bin/perl

use strict;
use warnings;

use XML::LibXML;
use Template;
use DBD::SQLite;
use CGI;
use Parse::RecDescent;
use List::MoreUtils;
use Moose;

print quot;Hello Worldnquot;;
Make an executable

ā€¢ perl -MCPAN -e ā€˜install PAR::Packerā€™
ā€¢ pp -o hellow hellow.pl
ā€¢ ...copy ā€œhellowā€ to new computer
ā€¢ ./hellow
  Hello World
#!/usr/bin/perl

use strict;
use warnings;

print quot;Hello Worldnquot;;
Build our own Perl and
 ship the whole thing
Get Stable Perl

ā€¢ lwp-request $CPAN_URL >
  perl-5.8.8.tar.gz
ā€¢ gunzip -c perl-5.8.8.tar.gz | tar -xvf -
ā€¢ cd perl-5.8.8
Tell it where to go


ā€¢ mkdir -p /User/mark/bin/perl5.8.8
ā€¢ ./conļ¬gure.gnu --preļ¬x=/User/mark/bin/
  perl5.8.8
Install it

ā€¢ make
ā€¢ make test
ā€¢ make install
We now have our own
    perl in ~/bin
We can install itā€™s own
     modules
~/bin/perl5.8.8/bin/perl
  -MCPAN -e ā€˜install
       Templateā€™
Problem: different paths

ā€¢ /home/mark/bin/myperl
ā€¢ /home/mfowler/bin/myperl
ā€¢ /home/nisuser/bin/myperl
mv ~/bin/perl5.8.8
    whatever
whatever/bin/perl -e
  ā€˜use Storableā€™
Can't locate Storable.pm in @INC (@INC
  contains: /User/mark/bin/perl5.8.8/lib/5.8.8/
   darwin-2level /User/mark/bin/perl5.8.8/lib/
  5.8.8 /User/mark/bin/perl5.8.8/lib/site_perl/
5.8.8/darwin-2level /User/mark/bin/perl5.8.8/lib/
  site_perl/5.8.8 /User/mark/bin/perl5.8.8/lib/
             site_perl .) at -e line 1.
Can't locate Storable.pm in @INC (@INC
  contains: /User/mark/bin/perl5.8.8/lib/5.8.8/
   darwin-2level /User/mark/bin/perl5.8.8/lib/
  5.8.8 /User/mark/bin/perl5.8.8/lib/site_perl/
5.8.8/darwin-2level /User/mark/bin/perl5.8.8/lib/
  site_perl/5.8.8 /User/mark/bin/perl5.8.8/lib/
             site_perl .) at -e line 1.
Can't locate Storable.pm in @INC (@INC
    contains: ../lib/5.8.8/darwin-2level
                       ../lib/5.8.8
     ../lib/site_perl/5.8.8/darwin-2level
                ../lib/site_perl/5.8.8
          ../lib/site_perl .) at -e line 1.
bleed to the rescue
B
                                              E
                                                 TA
        Get Bleed Perl

ā€¢ lwp-request $CPAN_URL >
  perl-5.9.5.tar.gz
ā€¢ gunzip -c perl-5.9.5.tar.gz | tar -xvf -
ā€¢ cd perl-5.9.5
B
                                               E
                                                  TA
   Tell it where to go


ā€¢ mkdir -p /User/mark/bin/perl5.9.5
ā€¢ ./Conļ¬gure -Dusedevel -Dpreļ¬x=/User/
  mark/bin/perl5.9.5 -Duserelocatableinc -d
B
                                               E
                                                  TA
   Tell it where to go


ā€¢ mkdir -p /User/mark/bin/perl5.9.5
ā€¢ ./Conļ¬gure -Dusedevel -Dpreļ¬x=/User/
  mark/bin/perl5.9.5 -Duserelocatableinc -d
B
                               E
                                  TA
                 Install it

ā€¢ make
ā€¢ make test
ā€¢ make install
B
                      E
                         TA




mv ~/bin/perl5.9.5
    whatever
B
                          E
                             TA




whatever/bin/perl5.9.5
  -e ā€˜use Storableā€™
Exception Handling
Java
try {
  throw new NoCheeseException(ā€œredoā€);
} catch (NoCheeseException e) {
  system.err.println(e.toString());
}
Perl
eval {
  die new NoCheeseError->new(ā€œredoā€);
};
if (blessed($@) &&
  $@->isa(ā€œNoCheeseExceptionā€)) {
  print STDERR $@;
} elsif ($@) { die $@ }
Perl has SUCKY
   SYNTAX
Sins include:
Perl
eval {
  die new NoCheeseError->new(ā€œredoā€);
};
if (blessed($@) &&
  $@->isa(ā€œNoCheeseExceptionā€)) {
  print STDERR $@;
} elsif ($@) { die $@ }
die ā€œstop my programā€;
die ā€œsome catchable exceptionā€;
Perl
eval {
  die new NoCheeseError->new(ā€œredoā€);
};
if (blessed($@) &&
  $@->isa(ā€œNoCheeseExceptionā€)) {
  print STDERR $@;
} elsif ($@) { die $@ }
eval ā€œsome code to be compiledā€;
eval {
  # run some code to catch errors in
};
Perl
eval {
  die new NoCheeseError->new(ā€œredoā€);
};
if (blessed($@) &&
  $@->isa(ā€œNoCheeseExceptionā€)) {
  print STDERR $@;
} elsif ($@) { die $@ }
Perl
eval {
  die new NoCheeseError->new(ā€œredoā€);
};
if (blessed($@) &&
  $@->isa(ā€œNoCheeseExceptionā€)) {
  print STDERR $@;
} elsif ($@) { die $@ }
We can ļ¬x it!
(still) Perl
try {
  throw NoCheeseException ā€œredoā€;
}
catch NoCheeseException with {
   print STDERR $@;
};
try {
  throw NoCheeseException ā€œredoā€;
}
catch NoCheeseException with {
   print STDERR $@;
}
catch AnotherError with {
  print STDERR ā€œoopsnā€;
};
try {
  throw NoCheeseException ā€œredoā€;
}
catch NoCheeseException with {
   print STDERR $@;
}
catch AnotherError with {
  print STDERR ā€œoopsnā€;
};
try( sub {
   throw NoCheeseException ā€œredoā€;
},
catch NoCheeseException with(sub {
    print STDERR $@;
},
catch AnotherError with(sub {
   print STDERR ā€œoopsnā€;
})));
try( sub {
   throw NoCheeseException ā€œredoā€;
},
catch NoCheeseException with(sub {
    print STDERR $@;
},
catch AnotherError with(sub {
   print STDERR ā€œoopsnā€;
})));
try( sub {
   NoCheeseException->throw( ā€œredoā€ );
},
NoCheeseException->catch( with(sub {
    print STDERR $@;
},
AnotherError->catch( with(sub {
   print STDERR ā€œoopsnā€;
})))));
sub with (&;@) {
  return @_
}
try( sub {
   NoCheeseException->throw( ā€œredoā€ );
},
NoCheeseException->catch( with(sub {
    print STDERR $@;
},
AnotherError->catch( with(sub {
   print STDERR ā€œoopsnā€;
})))));
try( sub {
   NoCheeseException->throw( ā€œredoā€ );
},
NoCheeseException->catch( sub {
    print STDERR $@;
},
AnotherError->catch( sub {
   print STDERR ā€œoopsnā€;
})));
package OurErrorSuperclass;

sub catch {
  my $class = shift;
  my $action = shift;
  return +{
    class => $class,
    action => $action
  }, @_;
}
try( sub {
   NoCheeseException->throw( ā€œredoā€ );
},
NoCheeseException->catch( sub {
    print STDERR $@;
},
AnotherError->catch( sub {
   print STDERR ā€œoopsnā€;
})));
try( sub {
   NoCheeseException->throw( ā€œredoā€ );
},
NoCheeseException->catch( sub {
    print STDERR $@;
}, +{
   class => ā€œAnotherErrorā€,
   action => sub { print STDERR ā€œoopsnā€ }
}));
try( sub {
  NoCheeseException->throw( ā€œredoā€ );
}, +{
  class => ā€œNoCheeseExceptionā€,
  action => sub { print STDERR $@; }
}, +{
  class => ā€œAnotherErrorā€,
  action => sub { print STDERR ā€œoopsnā€ }
});
try( sub {
  NoCheeseException->throw( ā€œredoā€ );
}, +{
  class => ā€œNoCheeseExceptionā€,
  action => sub { print STDERR $@; }
}, +{
  class => ā€œAnotherErrorā€,
  action => sub { print STDERR ā€œoopsnā€ }
});
try( sub {
  NoCheeseException->throw( ā€œredoā€ );
}, +{
  class => ā€œNoCheeseExceptionā€,
  action => sub { print STDERR $@; }
}, +{
  class => ā€œAnotherErrorā€,
  action => sub { print STDERR ā€œoopsnā€ }
});
try( sub {
  NoCheeseException->throw( ā€œredoā€ );
}, +{
  class => ā€œNoCheeseExceptionā€,
  action => sub { print STDERR $@; }
}, +{
  class => ā€œAnotherErrorā€,
  action => sub { print STDERR ā€œoopsnā€ }
});
(still) Perl
try {
  throw NoCheeseException ā€œredoā€;
}
catch NoCheeseException with {
   print STDERR $@;
};
sub foo {
  try {
    return ā€œThis doesnā€™t return from fooā€;
  }
  catch NoCheeseException with {
     print STDERR $@;
  };
}
sub foo {
  eval {
    return ā€œThis doesnā€™t return from fooā€;
  };
  if ($@) { .... }
}
sub foo {
  try {
    return ā€œThis doesnā€™t return from fooā€;
  }
  catch NoCheeseException with {
     print STDERR $@;
  };
}
sub foo {
  try {
    rreturn ā€œThis doesnā€™t return from fooā€;
  }
  catch NoCheeseException with {
     print STDERR $@;
  } and return allowed;
}
sub foo {
  try {
    rreturn ā€œThis doesnā€™t return from fooā€;
  }
  catch NoCheeseException with {
     print STDERR $@;
  } and return allowed;
}
MyException


      NoDairyException
                                            NoSpreadException


 NoMilkException
                             NoButterException

                                                 NoMargException

                       NoCheeseException


NoEdamException        NoStiltonException         NoBrieException
package NoDairyException;
our @ISA = qw(MyError);

package NoMilkException;
our @ISA = qw(NoDairyException);

package NoSpreadException;
our @ISA = qw(NoDairyException);

package NoButterException;
our @ISA = qw(NoSpreadException);

package NoMargException;
our @ISA = qw(NoMargeException);

package NoCheeseException;
our @ISA = qw(NoDairyException);

package NoEdamException;
our @ISA = qw(NoCheeseException);

package NoStiltonException;
our @ISA = qw(NoCheeseException);

package NoBrieException;
our@ISA = qw(NoCheeseException);
Exceptions::deļ¬ne {
  exception NoDairyException;
  exception NoSpreadException extends NoDairyException;
  exception NoButterException extends NoSpreadException;
  exception NoMargException extends NoSpreadException;
  exception NoMilkException extends NoDairyException;
  exception NoCheeseException extends NoDairyException;
  exception NoEdamException extends NoCheeseException;
  exception NoStiltonException extends NoCheeseException;
  exception NoBrieException extends NoCheeseException;
};
But itā€™s a scripting
    language!
Donā€™t you just love the
  Template Toolkit?
bash$ tpage
[% FOR a = [1..5]; a; END %]
^D
12345
bash$
#!perl

$whereami = ā€œViennaā€;
print ā€œHello $whereami!nā€;
#!tpage

[% whereami = ā€œViennaā€ -%]
Hello [% whereami %]!
bash$ ./hellov.tp
bash$ ./hellov.tp
-bash: ./hellov.tp: tpage: bad interpreter:
No such ļ¬le or directory
where bash ļ¬nds the
          Executable code to
#!tpage    load into memory


[% whereami = ā€œViennaā€ -%]
Hello [% whereami %]!
bash$ cat tpage
#!/usr/bin/perl -w
use strict;
use Template;
use AppConļ¬g;
ā€¦
Two possible solutions
Method one:
Abuse source ļ¬lters
ā€¢ ā€œSource ļ¬lters are a way to change your
  source code before perl gets to see itā€
#!/usr/bin/perl

use strict;
use warnings;

use EnableDebugging;

# DEBUG printing stuff out
print quot;hinquot;;
#!/usr/bin/perl

use strict;
use warnings;

use EnableDebugging;

;print STDERR ā€œDEBUG: printing stuff outnā€;
print quot;hinquot;;
package EnableDebugging;
use Filter::Simple;

FILTER {
  s{#s*DEBUGs+(.*)}
    {;print STDERR q<DEBUG: $1>, quot;nquot;;};
};

1;
package EnableDebugging;
use Filter::Simple;

FILTER {
  s{#s*DEBUGs+(.*)}
    {;print STDERR q<DEBUG: $1>, quot;nquot;;};
};

1;
package tpage;
use Filter::Simple;

FILTER {
  s{#s*DEBUGs+(.*)}
    {;print STDERR q<DEBUG: $1>, quot;nquot;;};
};

1;
package tpage;
use Filter::Simple;

FILTER {
  s{#s*DEBUGs+(.*)}
    {;print STDERR q<DEBUG: $1>, quot;nquot;;};
};

1;
package tpage;
use Filter::Simple;

FILTER {
   $template .= $_;
   $_ = ā€œā€;
};

1;
package tpage;
use Filter::Simple;

FILTER {
   $template .= $_;
   $_ = ā€œā€;
};

END {
  use Template;
  Template->new->process($template);
}
#!/usr/bin/perl
use tpage;

[%- whereami = ā€œViennaā€ -%]
Hello [% whereami %]!
2. Build our own
   executable
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

int main(int argc, char **argv, char **env)
{
  char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot; };

    PERL_SYS_INIT3(&argc,&argv,&env);
    my_perl = perl_alloc();
    perl_construct(my_perl);

    perl_parse(my_perl, NULL, 3, embedding, NULL);
    PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END;
    perl_run(my_perl);

    eval_pv(quot;print qq'oh hainā€™;quot;, TRUE);

    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}
(    stolen from
ā€œperldoc perlembedā€)
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

int main(int argc, char **argv, char **env)
{
  char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot; };

    PERL_SYS_INIT3(&argc,&argv,&env);
    my_perl = perl_alloc();
    perl_construct(my_perl);

    perl_parse(my_perl, NULL, 3, embedding, NULL);
    PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END;
    perl_run(my_perl);

    eval_pv(quot;print qq'o hain';quot;, TRUE);

    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

int main(int argc, char **argv, char **env)
{
  char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot; };

    PERL_SYS_INIT3(&argc,&argv,&env);
    my_perl = perl_alloc();
    perl_construct(my_perl);

    perl_parse(my_perl, NULL, 3, embedding, NULL);
    PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END;
    perl_run(my_perl);

    eval_pv(quot;print qqā€™o hainā€™;quot;, TRUE);

    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}
cc -o hellow hellow.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
bash$ ./hellow
    o hai
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

int main(int argc, char **argv, char **env)
{
  char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot; };

    PERL_SYS_INIT3(&argc,&argv,&env);
    my_perl = perl_alloc();
    perl_construct(my_perl);

    perl_parse(my_perl, NULL, 3, embedding, NULL);
    PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END;
    perl_run(my_perl);

    eval_pv(quot;print qq'o hain';quot;, TRUE);

    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

int main(int argc, char **argv, char **env)
{
  char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot; };

    PERL_SYS_INIT3(&argc,&argv,&env);
    my_perl = perl_alloc();
    perl_construct(my_perl);

    perl_parse(my_perl, NULL, 3, embedding, NULL);
    PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END;
    perl_run(my_perl);

    eval_pv(quot;print qqā€™o hainā€™;quot;, TRUE);

    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

int main(int argc, char **argv, char **env)
{
  char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot;, argv[0]};

    PERL_SYS_INIT3(&argc,&argv,&env);
    my_perl = perl_alloc();
    perl_construct(my_perl);

    perl_parse(my_perl, NULL, 4, embedding, NULL);
    PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END;
    perl_run(my_perl);

    eval_pv(quot;print qqā€™o hainā€™;quot;, TRUE);

    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

int main(int argc, char **argv, char **env)
{
  char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot;, argv[0]};

    PERL_SYS_INIT3(&argc,&argv,&env);
    my_perl = perl_alloc();
    perl_construct(my_perl);

    perl_parse(my_perl, NULL, 4, embedding, NULL);
    PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END;
    perl_run(my_perl);

    eval_pv(quot;print qqā€™o hainā€™;quot;, TRUE);

    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

int main(int argc, char **argv, char **env)
{
  char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot;, argv[0]};

    PERL_SYS_INIT3(&argc,&argv,&env);
    my_perl = perl_alloc();
    perl_construct(my_perl);

    perl_parse(my_perl, NULL, 4, embedding, NULL);
    PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END;
    perl_run(my_perl);

    eval_pv( ā€œuse Template 
      Template->new->process($ARGV[0])quot;, TRUE);
    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}
cc -o mytt mytt.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
now Executable code to
            load into memory
#!mytt

[% whereami = ā€œViennaā€ -%]
Hello [% whereami %]!
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

                                                   ā€œhellov.tpā€
int main(int argc, char **argv, char **env)
{
  char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot;, argv[0]};

    PERL_SYS_INIT3(&argc,&argv,&env);
    my_perl = perl_alloc();
    perl_construct(my_perl);

    perl_parse(my_perl, NULL, 4, embedding, NULL);
    PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END;
    perl_run(my_perl);

    eval_pv( ā€œuse Template 
      Template->new->process($ARGV[0])quot;, TRUE);
    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl;

                                                   ā€œhellov.tpā€
int main(int argc, char **argv, char **env)
{
  char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot;, argv[0]};

    PERL_SYS_INIT3(&argc,&argv,&env);
    my_perl = perl_alloc();
    perl_construct(my_perl);

    perl_parse(my_perl, NULL, 4, embedding, NULL);
    PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END;
    perl_run(my_perl);

    eval_pv( ā€œuse Template 
      Template->new->process($ARGV[0])quot;, TRUE);
    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}
A
                      LP
                           H
                            A




Weā€™ve already seen
  source ļ¬lters
B
                                                E
                                                   TA
                    PPI

ā€¢ Pure Perl parser
ā€¢ Only parses a subset of Perl
ā€¢ Canā€™t tell the difference between certain
  Perl constructs
ā€¢ This said - very very good at what it does
A
       LP
            H
             A




MAD
A
                                        LP
                                             H
                                              A



./conļ¬gure.gnu --preļ¬x=~/bin/perl595
        -Dusedevel -Dmad=y

 make && make test && make install
A
                  LP
                       H
                        A




 my $a = 1;
 my $b = 2;
print $a + $b;
A
                                   LP
                                        H
                                         A




PERL_XMLDUMP=quot;foo.xmlquot; ./perl foo.pl
</op_nextstate>
                                                                                                   A
                                                                                                     LP
                                                                              <op_sassign seq=quot;9 -> 10quot;
                                                                                                        H
                                                                         ļ¬‚ags=quot;VOID,KIDS,STACKEDquot;> A
<op_leave seq=quot;0 -> DONEquot; targ=quot;1quot; ļ¬‚ags=quot;VOID,KIDS,PARENSquot;
     private=quot;REFCOUNTEDquot;
     refcnt=quot;1quot;>
  <op_enter seq=quot;1 -> 2quot; />
  <op_null seq=quot;0 -> (2)quot; ļ¬‚ags=quot;VOIDquot;>
     <madprops>
        <mad_sv key=quot;;quot; val=quot;quot;/>
     </madprops>




                                                                                           <madprops>
  </op_null>
  <op_nextstate seq=quot;2 -> 3quot; ļ¬‚ags=quot;VOIDquot;
        line=quot;1quot;
        package=quot;mainquot;>
     <madprops>
        <mad_sv key=quot;;quot; val=quot;;quot;/>
        <mad_sv key=quot;#;quot; val=quot;&#xA;quot;/>
     </madprops>




                                                                             <mad_sv key=quot;oquot; val=quot;=quot;/>
  </op_nextstate>
  <op_sassign seq=quot;5 -> 6quot; ļ¬‚ags=quot;VOID,KIDS,STACKEDquot;>
     <madprops>
        <mad_sv key=quot;oquot; val=quot;=quot;/>
        <mad_sv key=quot;_oquot; val=quot; quot;/>
     </madprops>
     <op_const seq=quot;3 -> 4quot; ļ¬‚ags=quot;SCALARquot;
            IV=quot;1quot;>




                                                                            <mad_sv key=quot;_oquot; val=quot; quot;/>
        <madprops>
           <mad_sv key=quot;Xquot; val=quot;1quot;/>
           <mad_sv key=quot;_Xquot; val=quot; quot;/>
        </madprops>
     </op_const>
     <op_padsv seq=quot;4 -> 5quot; targ=quot;1quot; ļ¬‚ags=quot;SCALAR,REF,MOD,SPECIALquot;
           private=quot;INTROquot;>
        <madprops>




                                                                                           </madprops>
           <mad_sv key=quot;$quot; val=quot;$aquot;/>
           <mad_sv key=quot;_$quot; val=quot; quot;/>
           <mad_sv key=quot;dquot; val=quot;myquot;/>
           <mad_sv key=quot;_dquot; val=quot;quot;/>
        </madprops>
     </op_padsv>
  </op_sassign>
  <op_nextstate seq=quot;6 -> 7quot; ļ¬‚ags=quot;VOIDquot;




                                                                 <op_const seq=quot;7 -> 8quot; ļ¬‚ags=quot;SCALARquot;
        line=quot;2quot;
        package=quot;mainquot;>
     <madprops>
        <mad_sv key=quot;;quot; val=quot;;quot;/>
        <mad_sv key=quot;#;quot; val=quot;&#xA;quot;/>
     </madprops>
  </op_nextstate>
  <op_sassign seq=quot;9 -> 10quot; ļ¬‚ags=quot;VOID,KIDS,STACKEDquot;>
     <madprops>




                                                                                               IV=quot;2quot;>
        <mad_sv key=quot;oquot; val=quot;=quot;/>
        <mad_sv key=quot;_oquot; val=quot; quot;/>
     </madprops>
     <op_const seq=quot;7 -> 8quot; ļ¬‚ags=quot;SCALARquot;
            IV=quot;2quot;>
        <madprops>
           <mad_sv key=quot;Xquot; val=quot;2quot;/>
           <mad_sv key=quot;_Xquot; val=quot; quot;/>




                                                                                           <madprops>
        </madprops>
     </op_const>
     <op_padsv seq=quot;8 -> 9quot; targ=quot;2quot; ļ¬‚ags=quot;SCALAR,REF,MOD,SPECIALquot;
           private=quot;INTROquot;>
        <madprops>
           <mad_sv key=quot;$quot; val=quot;$bquot;/>
           <mad_sv key=quot;_$quot; val=quot; quot;/>
           <mad_sv key=quot;dquot; val=quot;myquot;/>




                                                                             <mad_sv key=quot;Xquot; val=quot;2quot;/>
        </madprops>
     </op_padsv>
  </op_sassign>
  <op_nextstate seq=quot;10 -> 11quot; ļ¬‚ags=quot;VOIDquot;
        line=quot;3quot;
        package=quot;mainquot;>
     <madprops>
        <mad_sv key=quot;;quot; val=quot;;quot;/>




                                                                            <mad_sv key=quot;_Xquot; val=quot; quot;/>
        <mad_sv key=quot;_;quot; val=quot;quot;/>
        <mad_sv key=quot;#;quot; val=quot;&#xA;quot;/>
     </madprops>
  </op_nextstate>
  <op_print seq=quot;15 -> 16quot; ļ¬‚ags=quot;SCALAR,KIDSquot;>
     <madprops>
        <mad_sv key=quot;oquot; val=quot;printquot;/>
     </madprops>




                                                                                           </madprops>
     <op_pushmark seq=quot;11 -> 12quot; ļ¬‚ags=quot;SCALARquot; />
     <op_add seq=quot;14 -> 15quot; targ=quot;3quot; ļ¬‚ags=quot;SCALAR,KIDSquot;>
        <madprops>
           <mad_sv key=quot;oquot; val=quot;+quot;/>
           <mad_sv key=quot;_oquot; val=quot; quot;/>
        </madprops>
        <op_padsv seq=quot;12 -> 13quot; targ=quot;1quot; ļ¬‚ags=quot;SCALARquot;>
           <madprops>




                                                                                           </op_const>
              <mad_sv key=quot;$quot; val=quot;$aquot;/>
              <mad_sv key=quot;_$quot; val=quot; quot;/>
           </madprops>
        </op_padsv>
        <op_padsv seq=quot;13 -> 14quot; targ=quot;2quot; ļ¬‚ags=quot;SCALARquot;>
           <madprops>
              <mad_sv key=quot;$quot; val=quot;$bquot;/>
              <mad_sv key=quot;_$quot; val=quot; quot;/>
           </madprops>




                                                                       <op_padsv seq=quot;8 -> 9quot; targ=quot;2quot;
        </op_padsv>
     </op_add>
  </op_print>
  <op_null seq=quot;0 -> (16)quot; ļ¬‚ags=quot;VOIDquot; />
</op_leave>




                                                                     ļ¬‚ags=quot;SCALAR,REF,MOD,SPECIALquot;
B::Generate


ā€¢ Can be used to create OP codes (i.e.
  compiled Perl code) directly from Perl
use B::Generate;
# Do nothing, slowly.
 CHECK {
  my $null = new B::OP(quot;nullquot;,0);
  my $enter = new B::OP(quot;enterquot;,0);
  my $cop = new B::COP(0, quot;hiyaquot;, 0);
  my $leave = new B::LISTOP(quot;leavequot;, 0, $enter, $null);
  $leave->children(3);
  $enter->sibling($cop);
  $enter->next($cop);
  $cop->sibling($null);
  $null->next($leave);
  $cop->next($leave);

     # Tell Perl where to ļ¬nd our tree.
     B::main_root($leave);
     B::main_start($enter);
 }
optomize.pm

ā€¢ Can be used to manipulate the OP codes
  after theyā€™ve loaded
ā€¢ Kinda like source ļ¬lters for compiled
  bypecode
Use?
ā€¢ PPI is reliable, but limited in itā€™s ability
 ā€¢ Easy to try to do too much with
ā€¢ Other techniques are very unstable / new
 ā€¢ B::Generate
 ā€¢ optomize
 ā€¢ MAD
A
                                                                                 LP
                                                                                      H
                                                                                       A
package main;
use typesafety; # 'summary', 'debug';

my FooBar $foo;            # establish type-checked variables
my FooBar $bar;            # FooBar is the base class of references $bar will hold
my BazQux $baz;

$foo = new FooBar;        # this is okay, because $foo holds FooBars
$bar = $foo;              # this is okay, because $bar also holds FooBars
# $foo = 10;              # this would throw an error - 10 is not a FooBar
# $baz = $foo;             # not allowed - FooBar isn't a BazQux
$foo = $baz;              # is allowed - BazQux is a FooBar because of inheritance
$bar = $foo->foo($baz, 1); # this is okay, as FooBar::foo() returns FooBars also

typesafety::check(); # perform type check static analysis
A
                                                                                 LP
                                                                                      H
                                                                                       A
package main;
use typesafety; # 'summary', 'debug';

my FooBar $foo;            # establish type-checked variables
my FooBar $bar;            # FooBar is the base class of references $bar will hold
my BazQux $baz;

$foo = new FooBar;        # this is okay, because $foo holds FooBars
$bar = $foo;              # this is okay, because $bar also holds FooBars
# $foo = 10;              # this would throw an error - 10 is not a FooBar
# $baz = $foo;             # not allowed - FooBar isn't a BazQux
$foo = $baz;              # is allowed - BazQux is a FooBar because of inheritance
$bar = $foo->foo($baz, 1); # this is okay, as FooBar::foo() returns FooBars also

typesafety::check(); # perform type check static analysis
A
                                                                                 LP
                                                                                      H
                                                                                       A
package main;
use typesafety; # 'summary', 'debug';

my FooBar $foo;            # establish type-checked variables
my FooBar $bar;            # FooBar is the base class of references $bar will hold
my BazQux $baz;

$foo = new FooBar;        # this is okay, because $foo holds FooBars
$bar = $foo;              # this is okay, because $bar also holds FooBars
# $foo = 10;              # this would throw an error - 10 is not a FooBar
# $baz = $foo;             # not allowed - FooBar isn't a BazQux
$foo = $baz;              # is allowed - BazQux is a FooBar because of inheritance
$bar = $foo->foo($baz, 1); # this is okay, as FooBar::foo() returns FooBars also

typesafety::check(); # perform type check static analysis
A
                                                                                 LP
                                                                                      H
                                                                                       A
package main;
use typesafety; # 'summary', 'debug';

my FooBar $foo;            # establish type-checked variables
my FooBar $bar;            # FooBar is the base class of references $bar will hold
my BazQux $baz;

$foo = new FooBar;        # this is okay, because $foo holds FooBars
$bar = $foo;              # this is okay, because $bar also holds FooBars
# $foo = 10;              # this would throw an error - 10 is not a FooBar
# $baz = $foo;             # not allowed - FooBar isn't a BazQux
$foo = $baz;              # is allowed - BazQux is a FooBar because of inheritance
$bar = $foo->foo($baz, 1); # this is okay, as FooBar::foo() returns FooBars also

typesafety::check(); # perform type check static analysis
Perl Sucks - and what to do about it

More Related Content

What's hot

Perl 5.28 new features
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new featuresbrian d foy
Ā 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & ToolsIan Barber
Ā 
Programming JVM Bytecode
Programming JVM BytecodeProgramming JVM Bytecode
Programming JVM BytecodeJoe Kutner
Ā 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6 brian d foy
Ā 
Unit testing with PHPUnit
Unit testing with PHPUnitUnit testing with PHPUnit
Unit testing with PHPUnitferca_sl
Ā 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLsAugusto Pascutti
Ā 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)brian d foy
Ā 
10 Catalyst Tips
10 Catalyst Tips10 Catalyst Tips
10 Catalyst TipsJay Shirley
Ā 
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Joseph Scott
Ā 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitmfrost503
Ā 
Zen: Building Maintainable Catalyst Applications
Zen: Building Maintainable Catalyst ApplicationsZen: Building Maintainable Catalyst Applications
Zen: Building Maintainable Catalyst ApplicationsJay Shirley
Ā 
SfCon: Test Driven Development
SfCon: Test Driven DevelopmentSfCon: Test Driven Development
SfCon: Test Driven DevelopmentAugusto Pascutti
Ā 
Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Contextlichtkind
Ā 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlHideaki Ohno
Ā 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trialbrian d foy
Ā 
On UnQLite
On UnQLiteOn UnQLite
On UnQLitecharsbar
Ā 
NTUSTxTDOH č³‡č؊安å…ØåŸŗē¤Žå·„作坊 åŸŗē¤Žé€†å‘ę•™č‚²čؓē·“
NTUSTxTDOH č³‡č؊安å…ØåŸŗē¤Žå·„作坊 åŸŗē¤Žé€†å‘ę•™č‚²čؓē·“NTUSTxTDOH č³‡č؊安å…ØåŸŗē¤Žå·„作坊 åŸŗē¤Žé€†å‘ę•™č‚²čؓē·“
NTUSTxTDOH č³‡č؊安å…ØåŸŗē¤Žå·„作坊 åŸŗē¤Žé€†å‘ę•™č‚²čؓē·“Sheng-Hao Ma
Ā 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinosbrian d foy
Ā 

What's hot (20)

Perl 5.28 new features
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new features
Ā 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
Ā 
Programming JVM Bytecode
Programming JVM BytecodeProgramming JVM Bytecode
Programming JVM Bytecode
Ā 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
Ā 
Unit testing with PHPUnit
Unit testing with PHPUnitUnit testing with PHPUnit
Unit testing with PHPUnit
Ā 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
Ā 
AssertJ quick introduction
AssertJ quick introductionAssertJ quick introduction
AssertJ quick introduction
Ā 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
Ā 
10 Catalyst Tips
10 Catalyst Tips10 Catalyst Tips
10 Catalyst Tips
Ā 
Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )Anatomy of a PHP Request ( UTOSC 2010 )
Anatomy of a PHP Request ( UTOSC 2010 )
Ā 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
Ā 
Perl IO
Perl IOPerl IO
Perl IO
Ā 
Zen: Building Maintainable Catalyst Applications
Zen: Building Maintainable Catalyst ApplicationsZen: Building Maintainable Catalyst Applications
Zen: Building Maintainable Catalyst Applications
Ā 
SfCon: Test Driven Development
SfCon: Test Driven DevelopmentSfCon: Test Driven Development
SfCon: Test Driven Development
Ā 
Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Context
Ā 
Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed Perl
Ā 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
Ā 
On UnQLite
On UnQLiteOn UnQLite
On UnQLite
Ā 
NTUSTxTDOH č³‡č؊安å…ØåŸŗē¤Žå·„作坊 åŸŗē¤Žé€†å‘ę•™č‚²čؓē·“
NTUSTxTDOH č³‡č؊安å…ØåŸŗē¤Žå·„作坊 åŸŗē¤Žé€†å‘ę•™č‚²čؓē·“NTUSTxTDOH č³‡č؊安å…ØåŸŗē¤Žå·„作坊 åŸŗē¤Žé€†å‘ę•™č‚²čؓē·“
NTUSTxTDOH č³‡č؊安å…ØåŸŗē¤Žå·„作坊 åŸŗē¤Žé€†å‘ę•™č‚²čؓē·“
Ā 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
Ā 

Similar to Perl Sucks - and what to do about it

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In PerlKang-min Liu
Ā 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationAttila Balazs
Ā 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.Workhorse Computing
Ā 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
Ā 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricksbrian d foy
Ā 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHPMarcello Duarte
Ā 
Cleancode
CleancodeCleancode
Cleancodehendrikvb
Ā 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlordsheumann
Ā 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perldaoswald
Ā 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de RailsFabio Akita
Ā 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
Ā 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
Ā 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationWorkhorse Computing
Ā 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Lucas Witold Adamus
Ā 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
Ā 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-productionAndrew Shitov
Ā 

Similar to Perl Sucks - and what to do about it (20)

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Ā 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
Ā 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.
Ā 
Modern Perl
Modern PerlModern Perl
Modern Perl
Ā 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
Ā 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
Ā 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
Ā 
Perl basics for Pentesters
Perl basics for PentestersPerl basics for Pentesters
Perl basics for Pentesters
Ā 
Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
Ā 
Cleancode
CleancodeCleancode
Cleancode
Ā 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
Ā 
SPL, not a bridge too far
SPL, not a bridge too farSPL, not a bridge too far
SPL, not a bridge too far
Ā 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perl
Ā 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de Rails
Ā 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
Ā 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
Ā 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
Ā 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
Ā 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Ā 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
Ā 

Recently uploaded

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
Ā 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
Ā 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
Ā 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
Ā 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
Ā 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
Ā 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
Ā 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
Ā 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
Ā 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
Ā 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
Ā 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
Ā 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
Ā 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
Ā 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
Ā 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
Ā 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
Ā 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
Ā 

Recently uploaded (20)

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
Ā 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Ā 
Hot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort ServiceHot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh šŸ” 9953056974 šŸ” Delhi escort Service
Ā 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
Ā 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Ā 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
Ā 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
Ā 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
Ā 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
Ā 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
Ā 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
Ā 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
Ā 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
Ā 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Ā 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Ā 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
Ā 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
Ā 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Ā 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
Ā 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
Ā 

Perl Sucks - and what to do about it

  • 1. Perl Sucks! (and what to do about it)
  • 2. What this talk is not ā€¢ ā€œWah, no one uses ā€˜use strictā€™ā€ ā€¢ ā€œPeopleā€™s perception of Perl is wrongā€ ā€¢ ā€œThe CPAN/mailing list/a other website isnā€™t exactly how I like itā€ ā€¢ ā€œThe garbage collection de-allocation routine isnā€™t very efļ¬centā€
  • 3. What this talk is ā€¢ Whatā€™s a few major annoyances with Perl ā€¢ What we the humble programmer can do to work around them
  • 4.
  • 10. -bash: jabme: /usr/local/bin/ perl: bad interpreter: No such ļ¬le or directory
  • 11. My Scripts Need ā€¢ A particular version of Perl ā€¢ A set of Perl modules
  • 12. PAR
  • 13. #!/usr/bin/perl use strict; use warnings; use XML::LibXML; use Template; use DBD::SQLite; use CGI; use Parse::RecDescent; use List::MoreUtils; use Moose; print quot;Hello Worldnquot;;
  • 14. Make an executable ā€¢ perl -MCPAN -e ā€˜install PAR::Packerā€™ ā€¢ pp -o hellow hellow.pl ā€¢ ...copy ā€œhellowā€ to new computer ā€¢ ./hellow Hello World
  • 15.
  • 17.
  • 18. Build our own Perl and ship the whole thing
  • 19. Get Stable Perl ā€¢ lwp-request $CPAN_URL > perl-5.8.8.tar.gz ā€¢ gunzip -c perl-5.8.8.tar.gz | tar -xvf - ā€¢ cd perl-5.8.8
  • 20. Tell it where to go ā€¢ mkdir -p /User/mark/bin/perl5.8.8 ā€¢ ./conļ¬gure.gnu --preļ¬x=/User/mark/bin/ perl5.8.8
  • 21. Install it ā€¢ make ā€¢ make test ā€¢ make install
  • 22. We now have our own perl in ~/bin
  • 23. We can install itā€™s own modules
  • 24. ~/bin/perl5.8.8/bin/perl -MCPAN -e ā€˜install Templateā€™
  • 25. Problem: different paths ā€¢ /home/mark/bin/myperl ā€¢ /home/mfowler/bin/myperl ā€¢ /home/nisuser/bin/myperl
  • 27. whatever/bin/perl -e ā€˜use Storableā€™
  • 28. Can't locate Storable.pm in @INC (@INC contains: /User/mark/bin/perl5.8.8/lib/5.8.8/ darwin-2level /User/mark/bin/perl5.8.8/lib/ 5.8.8 /User/mark/bin/perl5.8.8/lib/site_perl/ 5.8.8/darwin-2level /User/mark/bin/perl5.8.8/lib/ site_perl/5.8.8 /User/mark/bin/perl5.8.8/lib/ site_perl .) at -e line 1.
  • 29. Can't locate Storable.pm in @INC (@INC contains: /User/mark/bin/perl5.8.8/lib/5.8.8/ darwin-2level /User/mark/bin/perl5.8.8/lib/ 5.8.8 /User/mark/bin/perl5.8.8/lib/site_perl/ 5.8.8/darwin-2level /User/mark/bin/perl5.8.8/lib/ site_perl/5.8.8 /User/mark/bin/perl5.8.8/lib/ site_perl .) at -e line 1.
  • 30. Can't locate Storable.pm in @INC (@INC contains: ../lib/5.8.8/darwin-2level ../lib/5.8.8 ../lib/site_perl/5.8.8/darwin-2level ../lib/site_perl/5.8.8 ../lib/site_perl .) at -e line 1.
  • 31. bleed to the rescue
  • 32. B E TA Get Bleed Perl ā€¢ lwp-request $CPAN_URL > perl-5.9.5.tar.gz ā€¢ gunzip -c perl-5.9.5.tar.gz | tar -xvf - ā€¢ cd perl-5.9.5
  • 33. B E TA Tell it where to go ā€¢ mkdir -p /User/mark/bin/perl5.9.5 ā€¢ ./Conļ¬gure -Dusedevel -Dpreļ¬x=/User/ mark/bin/perl5.9.5 -Duserelocatableinc -d
  • 34. B E TA Tell it where to go ā€¢ mkdir -p /User/mark/bin/perl5.9.5 ā€¢ ./Conļ¬gure -Dusedevel -Dpreļ¬x=/User/ mark/bin/perl5.9.5 -Duserelocatableinc -d
  • 35. B E TA Install it ā€¢ make ā€¢ make test ā€¢ make install
  • 36. B E TA mv ~/bin/perl5.9.5 whatever
  • 37. B E TA whatever/bin/perl5.9.5 -e ā€˜use Storableā€™
  • 39. Java try { throw new NoCheeseException(ā€œredoā€); } catch (NoCheeseException e) { system.err.println(e.toString()); }
  • 40. Perl eval { die new NoCheeseError->new(ā€œredoā€); }; if (blessed($@) && $@->isa(ā€œNoCheeseExceptionā€)) { print STDERR $@; } elsif ($@) { die $@ }
  • 41. Perl has SUCKY SYNTAX
  • 43. Perl eval { die new NoCheeseError->new(ā€œredoā€); }; if (blessed($@) && $@->isa(ā€œNoCheeseExceptionā€)) { print STDERR $@; } elsif ($@) { die $@ }
  • 44. die ā€œstop my programā€;
  • 45. die ā€œsome catchable exceptionā€;
  • 46. Perl eval { die new NoCheeseError->new(ā€œredoā€); }; if (blessed($@) && $@->isa(ā€œNoCheeseExceptionā€)) { print STDERR $@; } elsif ($@) { die $@ }
  • 47. eval ā€œsome code to be compiledā€;
  • 48. eval { # run some code to catch errors in };
  • 49. Perl eval { die new NoCheeseError->new(ā€œredoā€); }; if (blessed($@) && $@->isa(ā€œNoCheeseExceptionā€)) { print STDERR $@; } elsif ($@) { die $@ }
  • 50. Perl eval { die new NoCheeseError->new(ā€œredoā€); }; if (blessed($@) && $@->isa(ā€œNoCheeseExceptionā€)) { print STDERR $@; } elsif ($@) { die $@ }
  • 52. (still) Perl try { throw NoCheeseException ā€œredoā€; } catch NoCheeseException with { print STDERR $@; };
  • 53. try { throw NoCheeseException ā€œredoā€; } catch NoCheeseException with { print STDERR $@; } catch AnotherError with { print STDERR ā€œoopsnā€; };
  • 54. try { throw NoCheeseException ā€œredoā€; } catch NoCheeseException with { print STDERR $@; } catch AnotherError with { print STDERR ā€œoopsnā€; };
  • 55. try( sub { throw NoCheeseException ā€œredoā€; }, catch NoCheeseException with(sub { print STDERR $@; }, catch AnotherError with(sub { print STDERR ā€œoopsnā€; })));
  • 56. try( sub { throw NoCheeseException ā€œredoā€; }, catch NoCheeseException with(sub { print STDERR $@; }, catch AnotherError with(sub { print STDERR ā€œoopsnā€; })));
  • 57. try( sub { NoCheeseException->throw( ā€œredoā€ ); }, NoCheeseException->catch( with(sub { print STDERR $@; }, AnotherError->catch( with(sub { print STDERR ā€œoopsnā€; })))));
  • 58. sub with (&;@) { return @_ }
  • 59. try( sub { NoCheeseException->throw( ā€œredoā€ ); }, NoCheeseException->catch( with(sub { print STDERR $@; }, AnotherError->catch( with(sub { print STDERR ā€œoopsnā€; })))));
  • 60. try( sub { NoCheeseException->throw( ā€œredoā€ ); }, NoCheeseException->catch( sub { print STDERR $@; }, AnotherError->catch( sub { print STDERR ā€œoopsnā€; })));
  • 61. package OurErrorSuperclass; sub catch { my $class = shift; my $action = shift; return +{ class => $class, action => $action }, @_; }
  • 62. try( sub { NoCheeseException->throw( ā€œredoā€ ); }, NoCheeseException->catch( sub { print STDERR $@; }, AnotherError->catch( sub { print STDERR ā€œoopsnā€; })));
  • 63. try( sub { NoCheeseException->throw( ā€œredoā€ ); }, NoCheeseException->catch( sub { print STDERR $@; }, +{ class => ā€œAnotherErrorā€, action => sub { print STDERR ā€œoopsnā€ } }));
  • 64. try( sub { NoCheeseException->throw( ā€œredoā€ ); }, +{ class => ā€œNoCheeseExceptionā€, action => sub { print STDERR $@; } }, +{ class => ā€œAnotherErrorā€, action => sub { print STDERR ā€œoopsnā€ } });
  • 65. try( sub { NoCheeseException->throw( ā€œredoā€ ); }, +{ class => ā€œNoCheeseExceptionā€, action => sub { print STDERR $@; } }, +{ class => ā€œAnotherErrorā€, action => sub { print STDERR ā€œoopsnā€ } });
  • 66. try( sub { NoCheeseException->throw( ā€œredoā€ ); }, +{ class => ā€œNoCheeseExceptionā€, action => sub { print STDERR $@; } }, +{ class => ā€œAnotherErrorā€, action => sub { print STDERR ā€œoopsnā€ } });
  • 67. try( sub { NoCheeseException->throw( ā€œredoā€ ); }, +{ class => ā€œNoCheeseExceptionā€, action => sub { print STDERR $@; } }, +{ class => ā€œAnotherErrorā€, action => sub { print STDERR ā€œoopsnā€ } });
  • 68. (still) Perl try { throw NoCheeseException ā€œredoā€; } catch NoCheeseException with { print STDERR $@; };
  • 69. sub foo { try { return ā€œThis doesnā€™t return from fooā€; } catch NoCheeseException with { print STDERR $@; }; }
  • 70. sub foo { eval { return ā€œThis doesnā€™t return from fooā€; }; if ($@) { .... } }
  • 71. sub foo { try { return ā€œThis doesnā€™t return from fooā€; } catch NoCheeseException with { print STDERR $@; }; }
  • 72. sub foo { try { rreturn ā€œThis doesnā€™t return from fooā€; } catch NoCheeseException with { print STDERR $@; } and return allowed; }
  • 73. sub foo { try { rreturn ā€œThis doesnā€™t return from fooā€; } catch NoCheeseException with { print STDERR $@; } and return allowed; }
  • 74. MyException NoDairyException NoSpreadException NoMilkException NoButterException NoMargException NoCheeseException NoEdamException NoStiltonException NoBrieException
  • 75. package NoDairyException; our @ISA = qw(MyError); package NoMilkException; our @ISA = qw(NoDairyException); package NoSpreadException; our @ISA = qw(NoDairyException); package NoButterException; our @ISA = qw(NoSpreadException); package NoMargException; our @ISA = qw(NoMargeException); package NoCheeseException; our @ISA = qw(NoDairyException); package NoEdamException; our @ISA = qw(NoCheeseException); package NoStiltonException; our @ISA = qw(NoCheeseException); package NoBrieException; our@ISA = qw(NoCheeseException);
  • 76. Exceptions::deļ¬ne { exception NoDairyException; exception NoSpreadException extends NoDairyException; exception NoButterException extends NoSpreadException; exception NoMargException extends NoSpreadException; exception NoMilkException extends NoDairyException; exception NoCheeseException extends NoDairyException; exception NoEdamException extends NoCheeseException; exception NoStiltonException extends NoCheeseException; exception NoBrieException extends NoCheeseException; };
  • 77. But itā€™s a scripting language!
  • 78. Donā€™t you just love the Template Toolkit?
  • 79. bash$ tpage [% FOR a = [1..5]; a; END %] ^D 12345 bash$
  • 80. #!perl $whereami = ā€œViennaā€; print ā€œHello $whereami!nā€;
  • 81. #!tpage [% whereami = ā€œViennaā€ -%] Hello [% whereami %]!
  • 83. bash$ ./hellov.tp -bash: ./hellov.tp: tpage: bad interpreter: No such ļ¬le or directory
  • 84. where bash ļ¬nds the Executable code to #!tpage load into memory [% whereami = ā€œViennaā€ -%] Hello [% whereami %]!
  • 85. bash$ cat tpage #!/usr/bin/perl -w use strict; use Template; use AppConļ¬g; ā€¦
  • 88. ā€¢ ā€œSource ļ¬lters are a way to change your source code before perl gets to see itā€
  • 89. #!/usr/bin/perl use strict; use warnings; use EnableDebugging; # DEBUG printing stuff out print quot;hinquot;;
  • 90. #!/usr/bin/perl use strict; use warnings; use EnableDebugging; ;print STDERR ā€œDEBUG: printing stuff outnā€; print quot;hinquot;;
  • 91. package EnableDebugging; use Filter::Simple; FILTER { s{#s*DEBUGs+(.*)} {;print STDERR q<DEBUG: $1>, quot;nquot;;}; }; 1;
  • 92. package EnableDebugging; use Filter::Simple; FILTER { s{#s*DEBUGs+(.*)} {;print STDERR q<DEBUG: $1>, quot;nquot;;}; }; 1;
  • 93. package tpage; use Filter::Simple; FILTER { s{#s*DEBUGs+(.*)} {;print STDERR q<DEBUG: $1>, quot;nquot;;}; }; 1;
  • 94. package tpage; use Filter::Simple; FILTER { s{#s*DEBUGs+(.*)} {;print STDERR q<DEBUG: $1>, quot;nquot;;}; }; 1;
  • 95. package tpage; use Filter::Simple; FILTER { $template .= $_; $_ = ā€œā€; }; 1;
  • 96. package tpage; use Filter::Simple; FILTER { $template .= $_; $_ = ā€œā€; }; END { use Template; Template->new->process($template); }
  • 97. #!/usr/bin/perl use tpage; [%- whereami = ā€œViennaā€ -%] Hello [% whereami %]!
  • 98. 2. Build our own executable
  • 99. #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot; }; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 3, embedding, NULL); PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); eval_pv(quot;print qq'oh hainā€™;quot;, TRUE); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
  • 100. ( stolen from ā€œperldoc perlembedā€)
  • 101. #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot; }; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 3, embedding, NULL); PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); eval_pv(quot;print qq'o hain';quot;, TRUE); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
  • 102. #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot; }; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 3, embedding, NULL); PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); eval_pv(quot;print qqā€™o hainā€™;quot;, TRUE); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
  • 103. cc -o hellow hellow.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
  • 104. bash$ ./hellow o hai
  • 105. #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot; }; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 3, embedding, NULL); PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); eval_pv(quot;print qq'o hain';quot;, TRUE); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
  • 106. #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot; }; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 3, embedding, NULL); PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); eval_pv(quot;print qqā€™o hainā€™;quot;, TRUE); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
  • 107. #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot;, argv[0]}; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 4, embedding, NULL); PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); eval_pv(quot;print qqā€™o hainā€™;quot;, TRUE); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
  • 108. #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot;, argv[0]}; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 4, embedding, NULL); PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); eval_pv(quot;print qqā€™o hainā€™;quot;, TRUE); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
  • 109. #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot;, argv[0]}; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 4, embedding, NULL); PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); eval_pv( ā€œuse Template Template->new->process($ARGV[0])quot;, TRUE); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
  • 110. cc -o mytt mytt.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
  • 111. now Executable code to load into memory #!mytt [% whereami = ā€œViennaā€ -%] Hello [% whereami %]!
  • 112. #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; ā€œhellov.tpā€ int main(int argc, char **argv, char **env) { char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot;, argv[0]}; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 4, embedding, NULL); PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); eval_pv( ā€œuse Template Template->new->process($ARGV[0])quot;, TRUE); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
  • 113. #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; ā€œhellov.tpā€ int main(int argc, char **argv, char **env) { char *embedding[] = { quot;quot;, quot;-equot;, quot;0quot;, argv[0]}; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 4, embedding, NULL); PL_exit_ļ¬‚ags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); eval_pv( ā€œuse Template Template->new->process($ARGV[0])quot;, TRUE); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
  • 114.
  • 115. A LP H A Weā€™ve already seen source ļ¬lters
  • 116. B E TA PPI ā€¢ Pure Perl parser ā€¢ Only parses a subset of Perl ā€¢ Canā€™t tell the difference between certain Perl constructs ā€¢ This said - very very good at what it does
  • 117. A LP H A MAD
  • 118. A LP H A ./conļ¬gure.gnu --preļ¬x=~/bin/perl595 -Dusedevel -Dmad=y make && make test && make install
  • 119. A LP H A my $a = 1; my $b = 2; print $a + $b;
  • 120. A LP H A PERL_XMLDUMP=quot;foo.xmlquot; ./perl foo.pl
  • 121. </op_nextstate> A LP <op_sassign seq=quot;9 -> 10quot; H ļ¬‚ags=quot;VOID,KIDS,STACKEDquot;> A <op_leave seq=quot;0 -> DONEquot; targ=quot;1quot; ļ¬‚ags=quot;VOID,KIDS,PARENSquot; private=quot;REFCOUNTEDquot; refcnt=quot;1quot;> <op_enter seq=quot;1 -> 2quot; /> <op_null seq=quot;0 -> (2)quot; ļ¬‚ags=quot;VOIDquot;> <madprops> <mad_sv key=quot;;quot; val=quot;quot;/> </madprops> <madprops> </op_null> <op_nextstate seq=quot;2 -> 3quot; ļ¬‚ags=quot;VOIDquot; line=quot;1quot; package=quot;mainquot;> <madprops> <mad_sv key=quot;;quot; val=quot;;quot;/> <mad_sv key=quot;#;quot; val=quot;&#xA;quot;/> </madprops> <mad_sv key=quot;oquot; val=quot;=quot;/> </op_nextstate> <op_sassign seq=quot;5 -> 6quot; ļ¬‚ags=quot;VOID,KIDS,STACKEDquot;> <madprops> <mad_sv key=quot;oquot; val=quot;=quot;/> <mad_sv key=quot;_oquot; val=quot; quot;/> </madprops> <op_const seq=quot;3 -> 4quot; ļ¬‚ags=quot;SCALARquot; IV=quot;1quot;> <mad_sv key=quot;_oquot; val=quot; quot;/> <madprops> <mad_sv key=quot;Xquot; val=quot;1quot;/> <mad_sv key=quot;_Xquot; val=quot; quot;/> </madprops> </op_const> <op_padsv seq=quot;4 -> 5quot; targ=quot;1quot; ļ¬‚ags=quot;SCALAR,REF,MOD,SPECIALquot; private=quot;INTROquot;> <madprops> </madprops> <mad_sv key=quot;$quot; val=quot;$aquot;/> <mad_sv key=quot;_$quot; val=quot; quot;/> <mad_sv key=quot;dquot; val=quot;myquot;/> <mad_sv key=quot;_dquot; val=quot;quot;/> </madprops> </op_padsv> </op_sassign> <op_nextstate seq=quot;6 -> 7quot; ļ¬‚ags=quot;VOIDquot; <op_const seq=quot;7 -> 8quot; ļ¬‚ags=quot;SCALARquot; line=quot;2quot; package=quot;mainquot;> <madprops> <mad_sv key=quot;;quot; val=quot;;quot;/> <mad_sv key=quot;#;quot; val=quot;&#xA;quot;/> </madprops> </op_nextstate> <op_sassign seq=quot;9 -> 10quot; ļ¬‚ags=quot;VOID,KIDS,STACKEDquot;> <madprops> IV=quot;2quot;> <mad_sv key=quot;oquot; val=quot;=quot;/> <mad_sv key=quot;_oquot; val=quot; quot;/> </madprops> <op_const seq=quot;7 -> 8quot; ļ¬‚ags=quot;SCALARquot; IV=quot;2quot;> <madprops> <mad_sv key=quot;Xquot; val=quot;2quot;/> <mad_sv key=quot;_Xquot; val=quot; quot;/> <madprops> </madprops> </op_const> <op_padsv seq=quot;8 -> 9quot; targ=quot;2quot; ļ¬‚ags=quot;SCALAR,REF,MOD,SPECIALquot; private=quot;INTROquot;> <madprops> <mad_sv key=quot;$quot; val=quot;$bquot;/> <mad_sv key=quot;_$quot; val=quot; quot;/> <mad_sv key=quot;dquot; val=quot;myquot;/> <mad_sv key=quot;Xquot; val=quot;2quot;/> </madprops> </op_padsv> </op_sassign> <op_nextstate seq=quot;10 -> 11quot; ļ¬‚ags=quot;VOIDquot; line=quot;3quot; package=quot;mainquot;> <madprops> <mad_sv key=quot;;quot; val=quot;;quot;/> <mad_sv key=quot;_Xquot; val=quot; quot;/> <mad_sv key=quot;_;quot; val=quot;quot;/> <mad_sv key=quot;#;quot; val=quot;&#xA;quot;/> </madprops> </op_nextstate> <op_print seq=quot;15 -> 16quot; ļ¬‚ags=quot;SCALAR,KIDSquot;> <madprops> <mad_sv key=quot;oquot; val=quot;printquot;/> </madprops> </madprops> <op_pushmark seq=quot;11 -> 12quot; ļ¬‚ags=quot;SCALARquot; /> <op_add seq=quot;14 -> 15quot; targ=quot;3quot; ļ¬‚ags=quot;SCALAR,KIDSquot;> <madprops> <mad_sv key=quot;oquot; val=quot;+quot;/> <mad_sv key=quot;_oquot; val=quot; quot;/> </madprops> <op_padsv seq=quot;12 -> 13quot; targ=quot;1quot; ļ¬‚ags=quot;SCALARquot;> <madprops> </op_const> <mad_sv key=quot;$quot; val=quot;$aquot;/> <mad_sv key=quot;_$quot; val=quot; quot;/> </madprops> </op_padsv> <op_padsv seq=quot;13 -> 14quot; targ=quot;2quot; ļ¬‚ags=quot;SCALARquot;> <madprops> <mad_sv key=quot;$quot; val=quot;$bquot;/> <mad_sv key=quot;_$quot; val=quot; quot;/> </madprops> <op_padsv seq=quot;8 -> 9quot; targ=quot;2quot; </op_padsv> </op_add> </op_print> <op_null seq=quot;0 -> (16)quot; ļ¬‚ags=quot;VOIDquot; /> </op_leave> ļ¬‚ags=quot;SCALAR,REF,MOD,SPECIALquot;
  • 122. B::Generate ā€¢ Can be used to create OP codes (i.e. compiled Perl code) directly from Perl
  • 123. use B::Generate; # Do nothing, slowly. CHECK { my $null = new B::OP(quot;nullquot;,0); my $enter = new B::OP(quot;enterquot;,0); my $cop = new B::COP(0, quot;hiyaquot;, 0); my $leave = new B::LISTOP(quot;leavequot;, 0, $enter, $null); $leave->children(3); $enter->sibling($cop); $enter->next($cop); $cop->sibling($null); $null->next($leave); $cop->next($leave); # Tell Perl where to ļ¬nd our tree. B::main_root($leave); B::main_start($enter); }
  • 124. optomize.pm ā€¢ Can be used to manipulate the OP codes after theyā€™ve loaded ā€¢ Kinda like source ļ¬lters for compiled bypecode
  • 125. Use? ā€¢ PPI is reliable, but limited in itā€™s ability ā€¢ Easy to try to do too much with ā€¢ Other techniques are very unstable / new ā€¢ B::Generate ā€¢ optomize ā€¢ MAD
  • 126.
  • 127. A LP H A package main; use typesafety; # 'summary', 'debug'; my FooBar $foo; # establish type-checked variables my FooBar $bar; # FooBar is the base class of references $bar will hold my BazQux $baz; $foo = new FooBar; # this is okay, because $foo holds FooBars $bar = $foo; # this is okay, because $bar also holds FooBars # $foo = 10; # this would throw an error - 10 is not a FooBar # $baz = $foo; # not allowed - FooBar isn't a BazQux $foo = $baz; # is allowed - BazQux is a FooBar because of inheritance $bar = $foo->foo($baz, 1); # this is okay, as FooBar::foo() returns FooBars also typesafety::check(); # perform type check static analysis
  • 128. A LP H A package main; use typesafety; # 'summary', 'debug'; my FooBar $foo; # establish type-checked variables my FooBar $bar; # FooBar is the base class of references $bar will hold my BazQux $baz; $foo = new FooBar; # this is okay, because $foo holds FooBars $bar = $foo; # this is okay, because $bar also holds FooBars # $foo = 10; # this would throw an error - 10 is not a FooBar # $baz = $foo; # not allowed - FooBar isn't a BazQux $foo = $baz; # is allowed - BazQux is a FooBar because of inheritance $bar = $foo->foo($baz, 1); # this is okay, as FooBar::foo() returns FooBars also typesafety::check(); # perform type check static analysis
  • 129. A LP H A package main; use typesafety; # 'summary', 'debug'; my FooBar $foo; # establish type-checked variables my FooBar $bar; # FooBar is the base class of references $bar will hold my BazQux $baz; $foo = new FooBar; # this is okay, because $foo holds FooBars $bar = $foo; # this is okay, because $bar also holds FooBars # $foo = 10; # this would throw an error - 10 is not a FooBar # $baz = $foo; # not allowed - FooBar isn't a BazQux $foo = $baz; # is allowed - BazQux is a FooBar because of inheritance $bar = $foo->foo($baz, 1); # this is okay, as FooBar::foo() returns FooBars also typesafety::check(); # perform type check static analysis
  • 130. A LP H A package main; use typesafety; # 'summary', 'debug'; my FooBar $foo; # establish type-checked variables my FooBar $bar; # FooBar is the base class of references $bar will hold my BazQux $baz; $foo = new FooBar; # this is okay, because $foo holds FooBars $bar = $foo; # this is okay, because $bar also holds FooBars # $foo = 10; # this would throw an error - 10 is not a FooBar # $baz = $foo; # not allowed - FooBar isn't a BazQux $foo = $baz; # is allowed - BazQux is a FooBar because of inheritance $bar = $foo->foo($baz, 1); # this is okay, as FooBar::foo() returns FooBars also typesafety::check(); # perform type check static analysis