Acme-Takahashi-Method

 view release on metacpan or  search on metacpan

lib/Acme/Takahashi/Method.pm  view on Meta::CPAN

our $VERSION = sprintf "%d.%02d", q$Revision: 0.1 $ =~ /(\d+)/g;
our $DEBUG = 0;

sub make_slide{
    my ($src, $columns, $rows) = @_;
    open my $in, "<:raw", $src or die "$src:$!";
    my $counter = 0;
    my $vspace = "\n" x ($rows/2 - 1);
    while(defined(my $line = <$in>)){
	$line =~ q/^use Acme::Takahashi::Method/ and next;
	$line =~ s/#.*//;
	$line =~ /^$/ and next;
	my $slide = "$src." . $counter++;
	$DEBUG and warn $slide;
	my $hspace = " " x (($columns - length($line))/2);
	my $next   =  sprintf(qq(do "$src.%d";), $counter);
	my $page      = "# $counter";
	my $pagespace = " " x ($columns - length($next) - length($page));
	open my $out, ">:raw", $slide or die "$slide : $!";
	print $out 
	    $vspace, $hspace, $line, $vspace, $next, $pagespace, $page, "\n";
	close $out;
    }
    return $counter;
}

sub do_slides{
    my $src = shift;
    do qq($src);
}

sub clobber{
   my ($src, $columns, $rows) = @_;
   use Config;
   my $vspace = "\n" x ($rows/2 - 1);
   my $line = "# $src";
   my $hspace = " " x (($columns - length($line))/2);
   my $next   =  qq(do "$src.0";);
   my $thisperl = $Config{perlpath};
   open my $out, ">:raw", $src or die "$src : $!";
   print $out "#!", $thisperl,
       $vspace, $hspace, $line, $vspace, $next, "\n";
   close $out;
}

sub show_slides{
    my ($src, $nslides) = @_;
    for my $slide ($src, map { "$src.$_" } (0 .. $nslides-1)){
	system "clear";
	open my $in, "<:raw", $slide or die "$slide : $!";
	print <$in>;
	close $in;
	my $key = getc;
    }
    system "clear";
}

sub import{
    my $pkg = shift;
    my %arg = @_;
    #use Data::Dumper;
    #print Dumper \%args;
    my $columns = $arg{columns} || 80;
    my $rows    = $arg{rows}    || 24;
    my $show_slide = !$arg{noslideshow} || 1;
    $arg{debug} and $DEBUG = 1;
    my $nslides = make_slide($0, $columns, $rows);
    clobber($0, $columns, $rows) unless $arg{noclobber};
    show_slides($0, $nslides) if $show_slide;
    do_slides($0) unless $arg{noexec};
    exit;
}

1;
__END__
# Below is stub documentation for your module. You'd better edit it!

=head1 NAME

Acme::Takahashi::Method - turns your script into slides accordingly to the Takahashi Method

=head1 SYNOPSIS

  use Acme::Takahashi::Method;
  # and the rest of your codes.

=head1 DESCRIPTION

The Takahashi Method L<http://www.rubycolor.org/takahashi/> is a
strong, powerful and impressive method that makes your presentation
something unforgettable.  This module makes your script as impressive
as those presentations.

Seeing is believing.  try

  cp eg/fact.pl
  perl -Ilib fact.pl 10

and see what I mean.

=head2 IMPORT DIRECTIVES

This module supports directives below.  You can set as many directives
as you like as follows;

  use Acme::Takahashi::Method columns => 132, rows => 50, noxec => 1;

=over 2

=item columns

Default is 80.  If you have larger terminals try

  use Acme::Takahashi::Method columns => 132;

or something.

=item rows

Default is 24.  If you have larger terminals try

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.058 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )