I, For One, Welcome Our New Perl6 Overlords

  • View
    2.609

  • Download
    1

  • Category

    Business

Preview:

DESCRIPTION

An introduction to (some of) the many Perl6 modules on CPAN today, and what you can do with them.

Citation preview

I, For One, Welcome Our New Perl6 Overlords

Josh Heumann

Perl6::________Perl6::AttributesPerl6::Bible Perl6::BindingPerl6::BuiltinsPerl6::CallerPerl6::ClassesPerl6::CommentsPerl6::ContextsPerl6::CurryingPerl6::DocPerl6::ExportPerl6::FormPerl6::GatherPerl6::Interpolate

Perl6::JunctionPerl6::ParametersPerl6::PerlPerl6::Perldoc Perl6::PlaceholdersPerl6::PugsPerl6::RolePerl6::Rules Perl6::SayPerl6::SlurpPerl6::Subs Perl6::TokenerPerl6::Variables

Perl6::Variables

use Perl6::Variables;

my @change_agents = ( 'consultancy', 'downsizing', 'knowledge management');

use Perl6::Variables;

my @change_agents = ( 'consultancy', 'downsizing', 'knowledge management');

print @change_agents[0];

use Perl6::Variables;

my @change_agents = ( 'consultancy', 'downsizing', 'knowledge management');

print @change_agents[0];

print @change_agents[1..2];

use Perl6::Variables;

my @change_agents = ( 'consultancy', 'downsizing', 'knowledge management');

print @change_agents[0];

print @change_agents[1..2];

# compile errorprint $change_agents[0];

use Perl6::Variables; # cont’d

%salaries = ( programmer => 77_000, dept_head => 90_000, ceo => 220_000,);

use Perl6::Variables; # cont’d

%salaries = ( programmer => 77_000, dept_head => 90_000, ceo => 220_000,);

print %salaries{ programmer };

use Perl6::Variables; # cont’d

%salaries = ( programmer => 77_000, dept_head => 90_000, ceo => 220_000,);

print %salaries{ programmer };

print $salaries{ ceo }; # compile error

use Perl6::Variables; # cont’d

# references$products = \@products;$benefits = \%benefits;

use Perl6::Variables; # cont’d

# references$products = \@products;$benefits = \%benefits;

print $products.[ 2 ];print $benefits.{ ceo };

use Perl6::Variables; # cont’d

# references$products = \@products;$benefits = \%benefits;

print $products.[ 2 ];print $benefits.{ ceo };

# doesn't exist, still undefprint $benefits.{ peon };

use Perl6::Variables; # cont’d

# you can slice@fired = @employees[ 1..2 ];

use Perl6::Variables; # cont’d

# you can slice@fired = @employees[ 1..2 ];

# you can diceprint %benefits{ ceo => 'janitor' };print %benefits{ 'manager', 'cto' };print %benefits{ qw(programmer designer) };

Perl6::Junction

use Perl6::Junction qw/ all none /;

use Perl6::Junction qw/ all none /;

# does anyone care?if( all( @level_of_interest ) < 0 ) { print 'review critical success factors';}

use Perl6::Junction qw/ all none /;

# does anyone care?if( all( @level_of_interest ) < 0 ) { print 'review critical success factors';}

# who is at this meeting?if( none( @attendee_rank ) eq 'boss' ) { print “let’s get some work done”;}

use Perl6::Junction qw/ any one /;

use Perl6::Junction qw/ any one /;

# any questions?if( any( @hands ) eq 'up' ) { print 'more synergising!';}

use Perl6::Junction qw/ any one /;

# any questions?if( any( @hands ) eq 'up' ) { print 'more synergising!';}

if( one( @types ) eq 'highlander' ) { print 'there can be only one';}

is any( one @listening ), '?';

use Perl6::Junction qw/ any all none one/;

# ok#'<', '<=', '>', '>=', '==', '!=',#'lt', 'le', 'gt', 'ge', 'eq', 'ne',

use Perl6::Junction qw/ any all none one/;

# ok#'<', '<=', '>', '>=', '==', '!=',#'lt', 'le', 'gt', 'ge', 'eq', 'ne',

use Perl6::Junction qw/ any all none one/;

# ok#'<', '<=', '>', '>=', '==', '!=',#'lt', 'le', 'gt', 'ge', 'eq', 'ne',

# not_ok# =~ !~

use Perl6::Junction qw/ all /;

use Perl6::Junction qw/ all /;

if( qr/^\d+$/ == all( @salaries ) ) { ...}

use Perl6::Junction qw/ all /;

if( qr/^\d+$/ == all( @salaries ) ) { ...}

if( all(@peon_salaries) <= @boss_salaries ){ ...}

use Perl6::Junction qw/ one any /;

my $meeting_time = any(2,4,6);

use Perl6::Junction qw/ one any /;

my $meeting_time = any(2,4,6);

use Perl6::Junction qw/ one any /;

my $meeting_time = any(2,4,6);

$VAR1 = bless( [ 2, 4, 6,], 'Perl6::Junction::Any' );

use Perl6::Junction qw/ one any /;

my $meeting_time = any(2,4,6);

$VAR1 = bless( [ 2, 4, 6,], 'Perl6::Junction::Any' );

if( $meeting_time == $current_time ){ # this is true at 2, 4, and 6 print ‘you have a meeting!’;}

Perl6::Slurp

use Perl6::Slurp;

$complete_manure = slurp 'report';

$ignore = slurp '<suggestion_box';

use Perl6::Slurp;

$corporate_vision = slurp \*STDIN;

use Perl6::Slurp;

$corporate_vision = slurp \*STDIN;

use Perl6::Slurp;

$corporate_vision = slurp \*STDIN;

$corporate_vision = slurp \$ceo_butt;

use Perl6::Slurp;

$corporate_vision = slurp \*STDIN;

$corporate_vision = slurp \$ceo_butt;

$corporate_vision = slurp 'ack ? myspace.log |';

use Perl6::Slurp;

$corporate_vision = slurp \*STDIN;

$corporate_vision = slurp \$ceo_butt;

$corporate_vision = slurp 'ack ? myspace.log |';

for( @random_books ) { $corporate_vision .= slurp;}

use Perl6::Slurp;

$corporate_vision = slurp \*STDIN;

$corporate_vision = slurp \$ceo_butt;

$corporate_vision = slurp 'ack ? myspace.log |';

for( @random_books ) { $corporate_vision .= slurp;}

$_ = undef;$corporate_vision = slurp;

Perl6::Perldoc

use Perl6::Perldoc;

=comment during crunch time, utilise our skill set to make sure we retain the optimal position.

use Perl6::Perldoc;

=comment during crunch time, utilise our skill set to make sure we retain the optimal position.

=for DATA this is a Perl 6 style DATA section

print <DATA>;

=for DATA you can have more than one of them

Perl6::Subs

use Perl6::Subs;

sub commoditize( $asset ) { # use $asset here as normal}

commoditize( 'product1' );

use Perl6::Subs;

sub commoditize (Array $assets) { # use $assets here as normal} commoditize( ['desks', 'chairs'] );

use Perl6::Subs;

sub commoditize (Array $assets, Str $name) { ...}

commoditize( ['widgets', 'doohickeys'], 'operation enduring money');

use Perl6::Subs;

sub commoditize (Array $assets, Str $name) { ...}

commoditize( ['widgets', 'doohickeys'], 'operation enduring money');

use Perl6::Subs;

sub commoditize (Array $assets, Str $name) { ...}

commoditize( ['widgets', 'doohickeys'], 'operation enduring money');

commoditize( ['health plan'] ); #shhhh

use Perl6::Subs;

sub commoditize (Array $assets, Str $name) { ...}

commoditize( ['widgets', 'doohickeys'], 'operation enduring money');

commoditize( ['health plan'] ); #shhhh

sub commoditize (Array $assets, Str ?$name) { ...}

use Perl6::Subs;

sub commoditize (Array $assets, Str $name) { ...}

commoditize( ['widgets', 'doohickeys'], 'operation enduring money');

commoditize( ['health plan'] ); #shhhh

use Perl6::Subs;

sub commoditize (Array $assets, Str $name) { ...}

commoditize( ['widgets', 'doohickeys'], 'operation enduring money');

commoditize( ['health plan'] ); #shhhh

sub commoditize (Array $assets, Str ?$name) { ...}

use Perl6::Subs;

{package Asset;

method divest (Sucker $buyer) { $self->sell( to => $buyer ); ... }

method commoditize ($class:) { print $class; }

}

Asset->commoditize();

Perl6::Parameters

Perl6::Say

use Perl6::Say;

say 'hi, bob!';

print "hi, bob.\n";

use Perl6::Say;

say 'hi, bob!';

print "hi, bob.\n";

say @hi;

use Perl6::Say;

say 'hi, bob!';

print "hi, bob.\n";

say @hi;say FH @hi;

use Perl6::Say;

say 'hi, bob!';

print "hi, bob.\n";

say @hi;say FH @hi;FH->say(@hi);

use Perl6::Say;

say 'hi, bob!';

print "hi, bob.\n";

say @hi;say FH @hi;FH->say(@hi);*FH->say(@hi);say $fh, @hi;$fh->say(@hi);

Perl6::Placeholders

growth

use Perl6::Placeholders;

my $grow = { $^a + $^b };

use Perl6::Placeholders;

my $grow = { $^a + $^b };

$grow->( 1, 2 );

use Perl6::Placeholders;

my $grow = { $^a + $^b };

$grow->( 1, 2 );

$grow->( $business, $random_acquisition );

use Perl6::Placeholders;

my $grow = { $^a + $^b };

$grow->( 1, 2 );

$grow->( $business, $random_acquisition );

# 3

# $bloat

use Perl6::Placeholders;

my @reports_without_coversheet = grep { ! $report->has_coversheet } @reports;

use Perl6::Placeholders;

my @reports_without_coversheet = grep { ! $report->has_coversheet } @reports;

my %tps_reports = map { $^rpt->name() => $^rpt->is_tps() } @reports;

Perl6::Binding

for my $group_budget ( @budgets ){ $group_budget -= 10;}

my %company = ( assets => { online => { static_services => [qw/ html_monkey data_entry /], tech => [qw/ programmer admins /], porn_sites => [ 'go _________ your __________' '___ me around the ________' 'what the parrot saw' ], }, sales => [qw/ groucho chico harpo zeppo gummo /], }, charities => { real => [], tax_shelters => [qw/ enron worldcom ceo-offspring_foundation /], },);

my %company = ( assets => { online => { static_services => [qw/ html_monkey data_entry /], tech => [qw/ programmer admins /], porn_sites => [ 'go _________ your __________' '___ me around the ________' 'what the parrot saw' ], }, sales => [qw/ groucho chico harpo zeppo gummo /], }, charities => { real => [], tax_shelters => [qw/ enron worldcom ceo-offspring_foundation /], },);

#$company->{ assets }->{ online }->{ static_services }

#$company->{ assets }->{ online }->{ static_services }

my $static_services = $company->{ assets }->{ products }->{ online }->{ static_services }

#$company->{ assets }->{ online }->{ static_services }

my $static_services = $company->{ assets }->{ products }->{ online }->{ static_services }

# manipulate $static_services here

$company->{ assets }->{ products }->{ online }->{ static_services } = $static_services;

use Perl6::Binding;

my $html_monkeys := $company->{ assets }->{ products }-> { online_solutions }->{ static_services };

# manipulate $static_services

use Perl6::Binding;

sub deny { my( $press_release, $conscience, @denials ) := *@_;

say "We cannot be held responsible for $_" for @denials; publish( $press_release );

$conscience->{ clean } = 1;}

# is our conscience is dirty?if( $conscience->{ clean } == 0 ) { deny( $press_release, $conscience, @denials );}

use Perl6::Binding;

sub deny { my( $press_release, $conscience, @denials ) := *@_;

say "We cannot be held responsible for $_" for @denials; publish( $press_release );

$conscience->{ clean } = 1;}

# is our conscience is dirty?if( $conscience->{ clean } == 0 ) { deny( $press_release, $conscience, @denials );}

# now our conscience is clean (ie, $conscience->{ clean } is 1)

use Perl6::Binding;

my @square_hole := %round_peg;my $one_meeting := @many_topics;

Perl6::Classes

use Perl6::Classes;

class Employee { has $.boss;}

class Manager { has @.meetings;}

use Perl6::Classes;

class Employee { has $.boss;}

class Manager is Employee { has @.meetings;}

use Perl6::Classes;

class Employee { has $.boss;

method take_a_labs_day is protected { ... }}

class Manager is Employee { has @.meetings;

method get_response is private { .... }}

use Perl6::Classes;

class CorporateClient is Client {

has $.name; has @.accounts; has %.meetings_by_date;

sub threaten { print "I own a bunch of shares..."; }}

use Perl6::Classes;

class CorporateClient is Client {

method complain { if( $.shares > 1_000_000 ) { print "sir! yes sir!\n"; } else { print "buy more shares\n"; } }}

Perl6::Attributesuse Perl6::Attributes;

sub print_client_information { my ($self) = @_; print $.name;

print @.purchases; print $.purchases[ 2 ]; print scalar @.purchases;

print keys %.complaints; print $.complaints{ RTFM };}

Perl6::Caller

# perl5

my ( $package, $filename, $line ) = caller;

use Perl6::Caller;

my $package = caller->package;my $filename = caller->filename;my $line_number = caller->line;

use Perl6::Caller;

my $package = caller->package;my $filename = caller->filename;my $line_number = caller->line;my $sub = caller->subroutine;

use Perl6::Caller;

my $package = caller->package;my $filename = caller->filename;my $line_number = caller->line;my $sub = caller->subroutine;my $is_require = caller->is_require;

use Perl6::Caller;

my $package = caller->package;my $filename = caller->filename;my $line_number = caller->line;my $sub = caller->subroutine;my $is_require = caller->is_require;my $hasargs = caller->hasargs;

use Perl6::Caller;

my $package = caller->package;my $filename = caller->filename;my $line_number = caller->line;my $sub = caller->subroutine;my $is_require = caller->is_require;my $hasargs = caller->hasargs;my $wantarray = caller->wantarray;

use Perl6::Caller;

my $caller = caller;

use Perl6::Caller;

my $caller = caller;

$caller->package;$caller->filename;$caller->line;$caller->subroutine;$caller->is_require;$caller->hasargs;$caller->wantarray;

use Perl6::Caller;

my $caller = caller;

$caller->package;$caller->filename;$caller->line;$caller->subroutine;$caller->is_require;$caller->hasargs;$caller->wantarray;

use Perl6::Caller;

my $caller = caller;

$caller->package;$caller->filename;$caller->line;$caller->subroutine;$caller->is_require;$caller->hasargs;$caller->wantarray;

Perl6::Interpolators

use Perl6::Interpolator;

print “the client says $($client->whinge)”;

use Perl6::Interpolator;

print “the client says $($client->whinge)”;

print “the agenda today: @($agenda->items)”;

use Perl6::Interpolator;

print “the client says $($client->whinge)”;

print “the agenda today: @($agenda->items)”;

print “the short version: $($agenda->items)”;

Perl6::Role

Perl6::Role

Perl6::Roles

Perl6::Roles

Perl6::Perl

Perl6::Builtins

Perl6::Gather

Perl6::Rules

Perl6::Rules

Perl6::Form

Perl6::ExportThe chief export of

is pain.

Perl6::Contexts

Perl6::Currying

Attribute::Handlers Attribute::Types Attribute::Overload Attribute::TieClasses Attribute::Util Attribute::Deprecated CLASS Class::Object Coro NEXT Scalar::Properties Switch Parrot::Embed Perl6::Attributes Perl6::Binding Perl6::Builtins Perl6::Caller Perl6::Classes Perl6::Contexts Perl6::Currying Perl6::Export

Perl6::Export::AttrsPerl6::FormPerl6::GatherPerl6::InterpolatorsPerl6::JunctionPerl6::ParametersPerl6::PerlPerl6::PerldocPerl6::PlaceholdersPerl6::PugsPerl6::RolesPerl6::RulesPerl6::SayPerl6::SlurpPerl6::SubsPerl6::TakePerl6::TokenerPerl6::VariablesRegexp::ParserUNIVERSAL::exportsWant

For more infomation

Perl6::Bundle

For more infomation

Questions?

Thanks!

• All of the Perl6::Bundle authors•(surprisingly not always Damian)•(also Luke Palmer)•Don Watson•OSDC•realestate.com.au•You

Josh Heumannjosh@joshheumann.com

Recommended