Skip to content

Instantly share code, notes, and snippets.

@mrkurt
Created October 8, 2008 16:02
Show Gist options
  • Save mrkurt/15552 to your computer and use it in GitHub Desktop.
Save mrkurt/15552 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
use strict;
use lib 'extlib', 'lib', '../lib';
my %opts;
use Getopt::Long;
GetOptions("type=s", \my($type),
"id=i", \my($id),
"cols=s", \my($cols),
"config=s", \my($cfg));
$type or die "usage: $0 --type=<type> [--id=<id>] [--cols=<columns>] [--config=<cfg>]";
use MT;
my $mt = MT->new(defined $cfg ? (Config => $cfg) : ()) or die MT->errstr;
my $class = MT->model($type);
die "Error loading '$type': $@" if $@;
my $itercount = 0;
my $iter = $class->load_iter($id ? { id => $id } : ()) or
die "Load failed: " . $class->errstr;
$cols = $cols ? [ split /\s*,\s*/, $cols ] : $class->column_names;
print join(':', @$cols), "\n";
while (my $obj = $iter->() && $itercount++ < 10) {
print join(':', map defined $obj->column($_) ? $obj->column($_) : '', @$cols), "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment