From casati_gianluca at yahoo.it Fri Mar 18 10:05:07 2011 From: casati_gianluca at yahoo.it (Gianluca Casati) Date: Fri, 18 Mar 2011 17:05:07 +0000 (GMT) Subject: [Milan-pm] Perl Node Interface Message-ID: <22827.96814.qm@web27903.mail.ukl.yahoo.com> Hi all ! First working version for PNI::GUI::Tk with cpan install PNI::GUI::Tk you should get PNI and a Tk GUI . Every feedback is welcome. -------------- next part -------------- An HTML attachment was scrubbed... URL: From casati_gianluca at yahoo.it Fri Mar 25 05:26:08 2011 From: casati_gianluca at yahoo.it (Gianluca Casati) Date: Fri, 25 Mar 2011 12:26:08 +0000 (GMT) Subject: [Milan-pm] Source code generation with Template Toolkit Message-ID: <720403.32534.qm@web27904.mail.ukl.yahoo.com> Hi all, I just wrote an article about Source code generation with Template ToolkitYou can read it here: http://perl-node-interface.blogspot.com/2011/03/source-code-generation-with-template.html Thanks to Marcos to share with me its solution ! -------------- next part -------------- An HTML attachment was scrubbed... URL: From oleber at gmail.com Fri Mar 25 07:22:31 2011 From: oleber at gmail.com (marcos rebelo) Date: Fri, 25 Mar 2011 15:22:31 +0100 Subject: [Milan-pm] Source code generation with Template Toolkit In-Reply-To: <720403.32534.qm@web27904.mail.ukl.yahoo.com> References: <720403.32534.qm@web27904.mail.ukl.yahoo.com> Message-ID: Thanks for the consideration. Lets reduce code ;) use strict; use warnings; use File::Find; use File::Spec; use Template; use Perl::Tidy; use Slurp; my $template_config = { STRICT => 1, DEBUG => 1, TRIM => 1 }; my $template = Template->new($template_config); find({ wanted => sub { if ( my ($output_path, $template_path) = ($File::Find::name =~ /((.)*\.tt2)$/ ) ) { print $template_path , "\n"; my $template_content = read_file($template_path); # naming convention: /path/to/my/file.ext.tt2 # is template file for /path/to/my/file.ext # if there is no /path/to/my/file.ext, just process /path/to/my/file.ext.tt2 if ( -e $output_path ) { print $output_path, "\n"; # process templates $template->process( \$template_content, {}, \my $output_content, { binmode => 1 } ) or warn $template->error # but if there is an error don't commit changes and next; # clean ^M chars ... i'm on Windows my $m_char = chr(13); $output_content =~ s/$m_char//g; # if it is a module or a test, tidy it if ( $output_path =~ /\.(pm|t)$/ ) { perltidy( source => \$output_content, destination => \my $output_content_tidy, argv => [] ); # replace content with its tidy version $output_content = $output_content_tidy; } write_file($output_path, $output_content); } } } File::Spec->curdir ); Best Regards MArcos 2011/3/25 Gianluca Casati : > Hi all, > > I just wrote an article about > > Source code generation with Template Toolkit > > You can read it here: > http://perl-node-interface.blogspot.com/2011/03/source-code-generation-with-template.html > > Thanks to Marcos to share with me its solution ! > > > _______________________________________________ > Milan-pm mailing list > Milan-pm at pm.org > http://mail.pm.org/mailman/listinfo/milan-pm > > -- Marcos Rebelo http://www.oleber.com/ Milan Perl Mongers leader https://sites.google.com/site/milanperlmongers/ Webmaster of http://perl5notebook.oleber.com From casati_gianluca at yahoo.it Fri Mar 25 11:11:31 2011 From: casati_gianluca at yahoo.it (Gianluca Casati) Date: Fri, 25 Mar 2011 18:11:31 +0000 (GMT) Subject: [Milan-pm] Source code generation with Template Toolkit In-Reply-To: References: <720403.32534.qm@web27904.mail.ukl.yahoo.com> Message-ID: <496904.9721.qm@web27905.mail.ukl.yahoo.com> Thank you again for your useful hints during our meetings, I really learned a lot of Perl ! It could be pretty reduced, but I had a problem with line terminators ... some ugly ^M appeared everywhere, I think it is a Windows related issue. Even with the { binmode => 1 } option I got ^M when calling templates from other templates with INCLUDE, PROCESS or WRAPPER directives. Probably this shorter code works pretty good on Linux, using paths instead of references ... use strict; use warnings; use File::Find; use File::Spec; use Template; my $template_config = { STRICT => 1, DEBUG => 1, TRIM => 1 }; my $template = Template->new($template_config); find( { wanted => sub { return unless /\.tt2$/; # naming convention: /path/to/my/file.ext.tt2 # is template file for /path/to/my/file.ext my $template_path = $File::Find::name; my $output_path = $template_path; $output_path =~ s/\.tt2$//; # process templates $template->process( $template_path, {}, $output_path, { binmode => 1 } ) or warn $template->error # but if there is an error don't commit changes and next; } }, File::Spec->curdir ); ... but if you then want to tidy code, using references it's worth it. Well, there are more than 100 ways to do it (and latins do it better :-) . ________________________________ Da: marcos rebelo A: milan-pm at pm.org Inviato: Ven 25 marzo 2011, 15:22:31 Oggetto: Re: [Milan-pm] Source code generation with Template Toolkit Thanks for the consideration. Lets reduce code ;) use strict; use warnings; use File::Find; use File::Spec; use Template; use Perl::Tidy; use Slurp; my $template_config = { STRICT => 1, DEBUG => 1, TRIM => 1 }; my $template = Template->new($template_config); find({ wanted => sub { if ( my ($output_path, $template_path) = ($File::Find::name =~ /((.)*\.tt2)$/ ) ) { print $template_path , "\n"; my $template_content = read_file($template_path); # naming convention: /path/to/my/file.ext.tt2 # is template file for /path/to/my/file.ext # if there is no /path/to/my/file.ext, just process /path/to/my/file.ext.tt2 if ( -e $output_path ) { print $output_path, "\n"; # process templates $template->process( \$template_content, {}, \my $output_content, { binmode => 1 } ) or warn $template->error # but if there is an error don't commit changes and next; # clean ^M chars ... i'm on Windows my $m_char = chr(13); $output_content =~ s/$m_char//g; # if it is a module or a test, tidy it if ( $output_path =~ /\.(pm|t)$/ ) { perltidy( source => \$output_content, destination => \my $output_content_tidy, argv => [] ); # replace content with its tidy version $output_content = $output_content_tidy; } write_file($output_path, $output_content); } } } File::Spec->curdir ); Best Regards MArcos 2011/3/25 Gianluca Casati : > Hi all, > > I just wrote an article about > > Source code generation with Template Toolkit > > You can read it here: >http://perl-node-interface.blogspot.com/2011/03/source-code-generation-with-template.html >l > > Thanks to Marcos to share with me its solution ! > > > _______________________________________________ > Milan-pm mailing list > Milan-pm at pm.org > http://mail.pm.org/mailman/listinfo/milan-pm > > -- Marcos Rebelo http://www.oleber.com/ Milan Perl Mongers leader https://sites.google.com/site/milanperlmongers/ Webmaster of http://perl5notebook.oleber.com _______________________________________________ Milan-pm mailing list Milan-pm at pm.org http://mail.pm.org/mailman/listinfo/milan-pm -------------- next part -------------- An HTML attachment was scrubbed... URL: