Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Get me excited about perl

by tobyink (Abbot)
on Sep 19, 2012 at 19:15 UTC ( #994503=note: print w/ replies, xml ) Need Help??

in reply to Get me excited about perl

use 5.010; use MooseX::DeclareX types => [ -Moose ]; class Worker { has task_list => ( traits => ['Array'], is => read_only, isa => ArrayRef[Str], handles => { add_task => 'push', next_task => 'shift', has_no_tasks => 'is_empty', }, ); build task_list { return []; } method do_work (Int $amount = 1) { for (1 .. $amount) { return if $self->has_no_tasks; say "Doing: ", $self->next_task; } } } role Lazy { before do_work { say "Work?! Do I have to?!" } } class Lazy::Worker extends Worker with Lazy; my $bob = Lazy::Worker->new; $bob->add_task($_) for ( "dig up the road", "pull out the broken pipes", "lay down new pipes", "fill in hole", ); $bob->do_work; $bob->do_work(2); $bob->do_work(3);
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Comment on Re: Get me excited about perl
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994503]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2015-11-28 11:14 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (741 votes), past polls