I, For One, Welcome Our New Perl6 Overlords

  • 1,826 views
Uploaded on

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

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

More in: Business , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to like this
No Downloads

Views

Total Views
1,826
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
25
Comments
1
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. I, For One, Welcome Our New Perl6 Overlords Josh Heumann
  • 2. Perl6::________ Perl6::Attributes Perl6::Junction Perl6::Bible Perl6::Parameters Perl6::Binding Perl6::Perl Perl6::Builtins Perl6::Perldoc Perl6::Caller Perl6::Placeholders Perl6::Classes Perl6::Pugs Perl6::Comments Perl6::Role Perl6::Contexts Perl6::Rules Perl6::Currying Perl6::Say Perl6::Doc Perl6::Slurp Perl6::Export Perl6::Subs Perl6::Form Perl6::Tokener Perl6::Gather Perl6::Variables Perl6::Interpolate
  • 3. Perl6::Variables
  • 4. use Perl6::Variables; my @change_agents = ( 'consultancy', 'downsizing', 'knowledge management' );
  • 5. use Perl6::Variables; my @change_agents = ( 'consultancy', 'downsizing', 'knowledge management' ); print @change_agents[0];
  • 6. use Perl6::Variables; my @change_agents = ( 'consultancy', 'downsizing', 'knowledge management' ); print @change_agents[0]; print @change_agents[1..2];
  • 7. use Perl6::Variables; my @change_agents = ( 'consultancy', 'downsizing', 'knowledge management' ); print @change_agents[0]; print @change_agents[1..2]; # compile error print $change_agents[0];
  • 8. use Perl6::Variables; # cont’d %salaries = ( programmer => 77_000, dept_head => 90_000, ceo => 220_000, );
  • 9. use Perl6::Variables; # cont’d %salaries = ( programmer => 77_000, dept_head => 90_000, ceo => 220_000, ); print %salaries{ programmer };
  • 10. use Perl6::Variables; # cont’d %salaries = ( programmer => 77_000, dept_head => 90_000, ceo => 220_000, ); print %salaries{ programmer }; print $salaries{ ceo }; # compile error
  • 11. use Perl6::Variables; # cont’d # references $products = @products; $benefits = %benefits;
  • 12. use Perl6::Variables; # cont’d # references $products = @products; $benefits = %benefits; print $products.[ 2 ]; print $benefits.{ ceo };
  • 13. use Perl6::Variables; # cont’d # references $products = @products; $benefits = %benefits; print $products.[ 2 ]; print $benefits.{ ceo }; # doesn't exist, still undef print $benefits.{ peon };
  • 14. use Perl6::Variables; # cont’d # you can slice @fired = @employees[ 1..2 ];
  • 15. use Perl6::Variables; # cont’d # you can slice @fired = @employees[ 1..2 ]; # you can dice print %benefits{ ceo => 'janitor' }; print %benefits{ 'manager', 'cto' }; print %benefits{ qw(programmer designer) };
  • 16. Perl6::Junction
  • 17. use Perl6::Junction qw/ all none /;
  • 18. use Perl6::Junction qw/ all none /; # does anyone care? if( all( @level_of_interest ) < 0 ) { print 'review critical success factors'; }
  • 19. 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”; }
  • 20. use Perl6::Junction qw/ any one /;
  • 21. use Perl6::Junction qw/ any one /; # any questions? if( any( @hands ) eq 'up' ) { print 'more synergising!'; }
  • 22. 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 ), '?';
  • 23. use Perl6::Junction qw/ any all none one /; # ok #'<', '<=', '>', '>=', '==', '!=', #'lt', 'le', 'gt', 'ge', 'eq', 'ne',
  • 24. use Perl6::Junction qw/ any all none one /; # ok #'<', '<=', '>', '>=', '==', '!=', #'lt', 'le', 'gt', 'ge', 'eq', 'ne',
  • 25. use Perl6::Junction qw/ any all none one /; # ok #'<', '<=', '>', '>=', '==', '!=', #'lt', 'le', 'gt', 'ge', 'eq', 'ne', # not_ok # =~ !~
  • 26. use Perl6::Junction qw/ all /;
  • 27. use Perl6::Junction qw/ all /; if( qr/^d+$/ == all( @salaries ) ) { ... }
  • 28. use Perl6::Junction qw/ all /; if( qr/^d+$/ == all( @salaries ) ) { ... } if( all(@peon_salaries) <= @boss_salaries ){ ... }
  • 29. use Perl6::Junction qw/ one any /; my $meeting_time = any(2,4,6);
  • 30. use Perl6::Junction qw/ one any /; my $meeting_time = any(2,4,6);
  • 31. use Perl6::Junction qw/ one any /; my $meeting_time = any(2,4,6); $VAR1 = bless( [ 2, 4, 6, ], 'Perl6::Junction::Any' );
  • 32. 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!’; }
  • 33. Perl6::Slurp
  • 34. use Perl6::Slurp; $complete_manure = slurp 'report'; $ignore = slurp '<suggestion_box';
  • 35. use Perl6::Slurp; $corporate_vision = slurp *STDIN;
  • 36. use Perl6::Slurp; $corporate_vision = slurp *STDIN;
  • 37. use Perl6::Slurp; $corporate_vision = slurp *STDIN; $corporate_vision = slurp $ceo_butt;
  • 38. use Perl6::Slurp; $corporate_vision = slurp *STDIN; $corporate_vision = slurp $ceo_butt; $corporate_vision = slurp 'ack ? myspace.log |';
  • 39. use Perl6::Slurp; $corporate_vision = slurp *STDIN; $corporate_vision = slurp $ceo_butt; $corporate_vision = slurp 'ack ? myspace.log |'; for( @random_books ) { $corporate_vision .= slurp; }
  • 40. 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;
  • 41. Perl6::Perldoc
  • 42. use Perl6::Perldoc; =comment during crunch time, utilise our skill set to make sure we retain the optimal position.
  • 43. 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
  • 44. Perl6::Subs
  • 45. use Perl6::Subs; sub commoditize( $asset ) { # use $asset here as normal } commoditize( 'product1' );
  • 46. use Perl6::Subs; sub commoditize (Array $assets) { # use $assets here as normal } commoditize( ['desks', 'chairs'] );
  • 47. use Perl6::Subs; sub commoditize (Array $assets, Str $name) { ... } commoditize( ['widgets', 'doohickeys'], 'operation enduring money' );
  • 48. use Perl6::Subs; sub commoditize (Array $assets, Str $name) { ... } commoditize( ['widgets', 'doohickeys'], 'operation enduring money' );
  • 49. use Perl6::Subs; sub commoditize (Array $assets, Str $name) { ... } commoditize( ['widgets', 'doohickeys'], 'operation enduring money' ); commoditize( ['health plan'] ); #shhhh
  • 50. use Perl6::Subs; sub commoditize (Array $assets, Str ?$name){{ $name) ... } commoditize( ['widgets', 'doohickeys'], 'operation enduring money' ); commoditize( ['health plan'] ); #shhhh
  • 51. use Perl6::Subs; sub commoditize (Array $assets, Str $name) { ... } commoditize( ['widgets', 'doohickeys'], 'operation enduring money' ); commoditize( ['health plan'] ); #shhhh
  • 52. use Perl6::Subs; sub commoditize (Array $assets, Str ?$name){{ $name) ... } commoditize( ['widgets', 'doohickeys'], 'operation enduring money' ); commoditize( ['health plan'] ); #shhhh
  • 53. use Perl6::Subs; { package Asset; method divest (Sucker $buyer) { $self->sell( to => $buyer ); ... } method commoditize ($class:) { print $class; } } Asset->commoditize();
  • 54. Perl6::Parameters
  • 55. Perl6::Say
  • 56. use Perl6::Say; say 'hi, bob!'; print quot;hi, bob.nquot;;
  • 57. use Perl6::Say; say 'hi, bob!'; print quot;hi, bob.nquot;; say @hi;
  • 58. use Perl6::Say; say 'hi, bob!'; print quot;hi, bob.nquot;; say @hi; say FH @hi;
  • 59. use Perl6::Say; say 'hi, bob!'; print quot;hi, bob.nquot;; say @hi; say FH @hi; FH->say(@hi);
  • 60. use Perl6::Say; say 'hi, bob!'; print quot;hi, bob.nquot;; say @hi; say FH @hi; FH->say(@hi); *FH->say(@hi); say $fh, @hi; $fh->say(@hi);
  • 61. Perl6::Placeholders
  • 62. growth
  • 63. use Perl6::Placeholders; my $grow = { $^a + $^b };
  • 64. use Perl6::Placeholders; my $grow = { $^a + $^b }; $grow->( 1, 2 );
  • 65. use Perl6::Placeholders; my $grow = { $^a + $^b }; $grow->( 1, 2 ); $grow->( $business, $random_acquisition );
  • 66. use Perl6::Placeholders; my $grow = { $^a + $^b }; #3 $grow->( 1, 2 ); # $bloat $grow->( $business, $random_acquisition );
  • 67. use Perl6::Placeholders; my @reports_without_coversheet = grep { ! $report->has_coversheet } @reports;
  • 68. use Perl6::Placeholders; my @reports_without_coversheet = grep { ! $report->has_coversheet } @reports; my %tps_reports = map { $^rpt->name() => $^rpt->is_tps() } @reports;
  • 69. Perl6::Binding
  • 70. for my $group_budget ( @budgets ){ $group_budget -= 10; }
  • 71. 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 /], }, );
  • 72. 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 /], }, );
  • 73. #$company->{ assets }->{ online }->{ static_services }
  • 74. #$company->{ assets }->{ online }->{ static_services } my $static_services = $company->{ assets }->{ products }->{ online }->{ static_services }
  • 75. #$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;
  • 76. use Perl6::Binding; my $html_monkeys := $company->{ assets }->{ products }-> { online_solutions }->{ static_services }; # manipulate $static_services
  • 77. use Perl6::Binding; sub deny { my( $press_release, $conscience, @denials ) := *@_; say quot;We cannot be held responsible for $_quot; for @denials; publish( $press_release ); $conscience->{ clean } = 1; } # is our conscience is dirty? if( $conscience->{ clean } == 0 ) { deny( $press_release, $conscience, @denials ); }
  • 78. use Perl6::Binding; sub deny { my( $press_release, $conscience, @denials ) := *@_; say quot;We cannot be held responsible for $_quot; 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)
  • 79. use Perl6::Binding; my @square_hole := %round_peg; my $one_meeting := @many_topics;
  • 80. Perl6::Classes
  • 81. use Perl6::Classes; class Employee { has $.boss; } class Manager { has @.meetings; }
  • 82. use Perl6::Classes; class Employee { has $.boss; } class Manager is Employee { has @.meetings; }
  • 83. 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 { .... } }
  • 84. use Perl6::Classes; class CorporateClient is Client { has $.name; has @.accounts; has %.meetings_by_date; sub threaten { print quot;I own a bunch of shares...quot;; } }
  • 85. use Perl6::Classes; class CorporateClient is Client { method complain { if( $.shares > 1_000_000 ) { print quot;sir! yes sir!nquot;; } else { print quot;buy more sharesnquot;; } } }
  • 86. Perl6::Attributes use Perl6::Attributes; sub print_client_information { my ($self) = @_; print $.name; print @.purchases; print $.purchases[ 2 ]; print scalar @.purchases; print keys %.complaints; print $.complaints{ RTFM }; }
  • 87. Perl6::Caller
  • 88. # perl5 my ( $package, $filename, $line ) = caller;
  • 89. use Perl6::Caller; my $package = caller->package; my $filename = caller->filename; my $line_number = caller->line;
  • 90. use Perl6::Caller; my $package = caller->package; my $filename = caller->filename; my $line_number = caller->line; my $sub = caller->subroutine;
  • 91. 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;
  • 92. 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;
  • 93. 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;
  • 94. use Perl6::Caller; my $caller = caller;
  • 95. use Perl6::Caller; my $caller = caller; $caller->package; $caller->filename; $caller->line; $caller->subroutine; $caller->is_require; $caller->hasargs; $caller->wantarray;
  • 96. use Perl6::Caller; my $caller = caller; $caller->package; $caller->filename; $caller->line; $caller->subroutine; $caller->is_require; $caller->hasargs; $caller->wantarray;
  • 97. use Perl6::Caller; my $caller = caller; $caller->package; $caller->filename; $caller->line; $caller->subroutine; $caller->is_require; $caller->hasargs; $caller->wantarray;
  • 98. Perl6::Interpolators
  • 99. use Perl6::Interpolator; print “the client says $($client->whinge)”;
  • 100. use Perl6::Interpolator; print “the client says $($client->whinge)”; print “the agenda today: @($agenda->items)”;
  • 101. use Perl6::Interpolator; print “the client says $($client->whinge)”; print “the agenda today: @($agenda->items)”; print “the short version: $($agenda->items)”;
  • 102. Perl6::Role
  • 103. Perl6::Role
  • 104. Perl6::Roles
  • 105. Perl6::Roles
  • 106. Perl6::Perl
  • 107. Perl6::Builtins
  • 108. Perl6::Gather
  • 109. Perl6::Rules
  • 110. Perl6::Rules
  • 111. Perl6::Form
  • 112. Perl6::Export The chief export of is pain.
  • 113. Perl6::Contexts
  • 114. Perl6::Currying
  • 115. Attribute::Handlers Perl6::Export::Attrs Attribute::Types Perl6::Form Attribute::Overload Perl6::Gather Attribute::TieClasses Perl6::Interpolators Attribute::Util Perl6::Junction Attribute::Deprecated Perl6::Parameters CLASS Perl6::Perl Class::Object Perl6::Perldoc Coro Perl6::Placeholders NEXT Perl6::Pugs Scalar::Properties Perl6::Roles Switch Perl6::Rules Parrot::Embed Perl6::Say Perl6::Attributes Perl6::Slurp Perl6::Binding Perl6::Subs Perl6::Builtins Perl6::Take Perl6::Caller Perl6::Tokener Perl6::Classes Perl6::Variables Perl6::Contexts Regexp::Parser Perl6::Currying UNIVERSAL::exports Perl6::Export Want
  • 116. For more infomation Perl6::Bundle
  • 117. For more infomation
  • 118. Questions?
  • 119. Thanks! • All of the Perl6::Bundle authors •(surprisingly not always Damian) •(also Luke Palmer) •Don Watson •OSDC •realestate.com.au •You
  • 120. Josh Heumann josh@joshheumann.com