IO::All and Spiffy "I'm going to talk about my modules." perl makes easy things easy printing to stdout is very easy interpolation is /really/ easy -- brilliant perl makes hard things possible, too so if something is hard, and isn't easy, something is wrong! my first module, Inline, make things that were hard (mixing C and Perl) trivial my latest module makes something very easy trivial: "Hello world.\n" > io("greetings.txt"); if string manipulation is easy, and that's all you need to do, why do you have to waste so much time with the file i/o to get the strings? $thoughts < io"./old-thoughts"; $thoughts =~ s/hate/love/g; $thoughts >> io"./new-thoughts"; is this too freaky for you? io("./your-stuff") << io("my-stuff"); is just my $stuff = io("./my-stuff")->all; io("./your-stuff")->print($stuff); overloaded operations are just shortcuts IO::All gives you one sub, io() io() is the same as IO::All->new() this is an abstraction for: files directories sockets pipes dbm mldbm web page email lots of TMTOWTDI three ways to slurp a file my $io = io("file.txt"); 1. my $text = join "\n", $io->chomp->slurp; 2. $io >> $text; 3. $text .= $$io; directories return other objects my $dir = io("./mydir"); while (my $io = $dir->next) { print $io->relative->pathname, " - ", $io->geline if $io->is_file; } print "$_\n" for io("./mydir")->All_Files; locking is usually a pain so it's abstracted my $io = io("myfile")->tie->lock; my @lines = <$io>; $io->close; idioms that just work io('-') > io('-'); # write stdin to stdout io('-') < io('-'); # write stdin to stdout $strio = io('-') > io('$'); $tmpio = io('?') < $strio; $tmpio->seek(0,0); $tmpio > io('='); io('file')->[42] = 'new line'; %{io"my-env"} = %ENV; always read a line: if closed, reopen and read again my $line = $io->getline || $io->getline; print $_ for io("dir"->all_dirs; # print dirs print $$_ for io("dir"->all_files(3); # print recursive dir content my $io = io('this/that/file')->assert < $string; # ensure it exists @chunks = io('x-file')->gelines('x'); # unsure?? @found = grep /xxx/, io('.')->all; # find things with that name localtime() >> io($_) for qw(x y z); # $all_text << io($_) for qw(x y z); # grabs text these are IO::All::LWP $html < io("http://example.com/Foo'); # GET $html > io("http://example.com/Foo'); # PUT $html >> io("http://example.com/Foo'); # POST $stuff < io("ftp://example.com/Foo'); $stuff > io("ftp://example.com/Foo'); for my $addr (io("suckers.txt")->chomp->slurp) { io->mailto($address)->subject("581%")-> # lost slide my $base = io("dev/cpan")->chdir; # chdir to dir, change back on obj destroy tiny forking web server: io(":8080")->fork->accept < io("index.html"); io(":8080")->fork->accept->( sub { $_[0] < io(-x $1 ? "./$1 |" : $1) if /^GET \/(.*) / } ); see, if you use the io object as a subref, it passes every line of the content to the subref passed as the first param Kwiki::* doesn't use IO::All but spoon does why does this function get propagated up? SPIFFY! "Spiffy is where I put all of my cool stuff, so I use Spiffy in everything I write." spiffy is a new object base class for perl it has deep magics it exports magic functions in addition to providing base methods everything it exports is further exported by its subclasses subclasses can export even more functions package SomethingNew; use SomethingSpiffy '-base', qw(this !that :those); everything in the ISA chain gets exported Exporter is called over and over Spiffy eat's base.pm's brain "I eat brains. I like it." Well, no. I put it in a container in case I need it later. it replaces its import() with its own import so these are equivalent: use Keen '-base'; use base 'Keen'; spiffy lets you declare your class attributes package This; use That '-base'; field 'x'; field 'y' => []; const pi => 3.1415; spiffy is selfless package Something; use Nifty '-Base'; # notice the Base not base sub double { my $value = $self->current->value; return $value * 2; } # defeat by putting () after method name Perl has an "interesting" way to call supermethods. sub doit { my $self = shift; $self->SUPER::doit(@_); $self->doitsomemore; } I stole from Simon: sub doit { super; $self->doitsomemore; } spiffy gives Perl real class mixins < qw(this :stuff !that); sub foo { super; ... } # creates a new isa chain # [ed: like M::S does, but not crappy, it seems]