|
Revision 4196, 0.8 kB
(checked in by takayama, 3 months ago)
|
|
* Set svn keywords
|
-
Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 | #!/usr/bin/perl -w |
|---|
| 2 | use strict; |
|---|
| 3 | |
|---|
| 4 | use lib 'extlib', 'lib', '../lib'; |
|---|
| 5 | |
|---|
| 6 | my %opts; |
|---|
| 7 | use Getopt::Long; |
|---|
| 8 | GetOptions("type=s", \my($type), |
|---|
| 9 | "id=i", \my($id), |
|---|
| 10 | "cols=s", \my($cols), |
|---|
| 11 | "config=s", \my($cfg)); |
|---|
| 12 | $type or die "usage: $0 --type=<type> [--id=<id>] [--cols=<columns>] [--config=<cfg>]"; |
|---|
| 13 | |
|---|
| 14 | use MT; |
|---|
| 15 | my $mt = MT->new(defined $cfg ? (Config => $cfg) : ()) or die MT->errstr; |
|---|
| 16 | my $class = MT->model($type); |
|---|
| 17 | |
|---|
| 18 | die "Error loading '$type': $@" if $@; |
|---|
| 19 | |
|---|
| 20 | my $iter = $class->load_iter($id ? { id => $id } : ()) or |
|---|
| 21 | die "Load failed: " . $class->errstr; |
|---|
| 22 | $cols = $cols ? [ split /\s*,\s*/, $cols ] : $class->column_names; |
|---|
| 23 | print join(':', @$cols), "\n"; |
|---|
| 24 | while (my $obj = $iter->()) { |
|---|
| 25 | print join(':', map defined $obj->column($_) ? $obj->column($_) : '', @$cols), "\n"; |
|---|
| 26 | } |
|---|