Showing posts with label moose. Show all posts
Showing posts with label moose. Show all posts

2010-01-06

LazyWeb? Solutions for using MX::Declare and PerlTidy?

Dear Lazyweb.

I've been fighting for a while with this minor headache.

Using PerlTidy and MooseX::Declare in conjunction results in pain.

Here is a sample of the sort of indentation that results:

Input:


use MooseX::Declare;

class Foo {

method Simple {
my $foo = 1;
$foo = $foo + 1;
if( $foo ) {
$foo++;
}
}

method SimpleArgs ( $arg, $arg ) {
my $foo = 1;
$foo = $foo + 1;
if( $foo ) {
$foo++;
}
}

method NamedArgs ( :$argname , :$otherarg ) {
my $foo = 1;
$foo = $foo + 1;
if( $foo ) {
$foo++;
}
}
}


And the indentation after going through PerlTidy:

use MooseX::Declare;

class Foo {

method Simple {

my $foo = 1;
$foo = $foo + 1;
if ($foo) {
$foo++;
}
}

method SimpleArgs( $arg, $arg ) {
my $foo = 1;
$foo = $foo + 1;
if ($foo) {
$foo++;
}
}

method NamedArgs( : $argname, : $otherarg ) {
my $foo = 1;
$foo = $foo + 1;
if ($foo) {
$foo++;
}
};
}


You might notice the second example is both ugly, and refuses to function.

I gripe about it every now and then to various peoples, and the results tend towards 2 options:

  • Don't use PerlTidy
  • Don't use MooseX::Declare

Neither of those are much of an option to me. I really like keeping formatting and indentation consistent right across a project, but hand adjusting everything is just too much pain.

Some people tell me that I should just tweak my editor to do this for me, but that hardly works, I am yet to see an editor that handles Perl indentation intelligently enough for my liking. Additionally, some editors don't even really have features that tidy indentation and clean up end-of-line whitespace yet, while supporting heaps of other features I want.

Lately, I've been swayed towards using Padre, and its a handy interface for Perl coding, but there's still a massive void in the domain of keeping code tidy. The very best I can find is the Padre PerlTidy plugin, but that has all the same caveats PerlTidy has, so in this case, "just using my editors features" results in PerlTidy being the weak point yet again.

As far as I can make out, there's nothing even slightly comparable to PerlTidy, I cannot seem to see anything else that does anything remotely like it, not even on a more simplistic scale.

So, Dear Lazyweb, please scratch my itch.

2009-12-09

PreAnnouncing the in-progress Git::PurePerl::CommitBuilder

When I blogged about how to create commits raw with git, it was really a prelude to show why I'm in progress of writing a simple API to do all the hard repetitive stuff, as well as clarify in my mind what was really necessary, so as to write a logical front-end for it.


The basic synopis example I propose will work like this:


use Git::PurePerl::CommitBuilder;

my $commitBuilder = Git::PurePerl::CommitBuilder->new(
repository => '/some/path/to/repository', # will use /some/path/to/repository/.git
auto_init => 1 # init the repository if it does not exist, without this, it will die.
);

my $commit = $commitBuilder->new_commit(
author => 'Bob Smooth',
email => 'bob@smooth.example.org',
parent => $commitBuilder->branch('SomeBranchName'),
);

$commit->add_file( name => "Foo.txt" , content => "This is the content of Foo.txt");

$commit->write(
timestamp => DateTime->now(),
branch => 'SomeBranchName', # write the commit to the top of this branch
update_head => 0 , # default.
message => "This is my first commit, I R a noob",
);

This would produce a file layout as such ( after checking it out ):

/some/path/to/repository/Foo.txt


This would be your average usecase. This enables you to add/update files and commit them to the branch, but leaving everything else intact.

Initially, supporting 'parent =>' will be limited to the commit-hash lookup so as not to discard history, and won't actually preserve any files from the previous commit in the new one. ( it will be as if the tip was rm ./* and then added files to for every commit, yeilding huge diffs ).

Although this is ideal for my use, its probably less practical for everyone else.


my $commit = $commitBuilder->new_commit(
author => 'Bob Smooth',
email => 'bob@smooth.example.org',
parent => $commitBuilder->branch('SomeBranchName'),
empty => 1
);


Will later be required to form empty-tree based commits.


$commit->delete_file( name => "Foo.txt" );
$commit->delete_dir( name => "Bar" );
$commit->get_content( file => "Foo.txt");


I'm still ambivalent how we'll support directories, they're a complicated issue.

This is how it might look:

# String name == split on delimiters
$code->add_file( name => 'path/relative/to/base/here', content => "Hello" );
# ArrayRef name = rightmost token = file.
$code->add_file( name => [qw( path relative to base here )], content => "Hello" );
# Support scalar refs too for people who want them.
$code->add_file( name => [qw( path relative to base here )], content => \"Hello" );
# Read the content from a filehandle.
open my $fh, '<', 'TheFile.txt'; $code->add_file( name => [qw( path relative to base here )], read => $fh );
# Read the content from a file by name
$code->add_file( name => [qw( path relative to base here )], read => 'TheFile.txt' );


But I worry about path/file disambiguation qualms. I can't just cheat here and offload it on the filesystem. I feel like being worried about this means I'm doing something wrong, but I can't place why.

This is a notion I'm toying with for clarity:

$code->add_file( name => 'Foo', in => 'some/path/here' ... );
$code->add_file( name => 'Foo', in => [qw( some path here )] );


That very last one would make implementation of certain things easier.

I guess people can speak up and tell me what they like, and what sucks =)