File: list-objects

package info (click to toggle)
movabletype-opensource 5.1.4%2Bdfsg-4%2Bdeb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 32,996 kB
  • sloc: perl: 197,285; php: 62,405; sh: 166; xml: 117; makefile: 83; sql: 32
file content (27 lines) | stat: -rwxr-xr-x 805 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/perl -w
use strict;
binmode STDOUT, ":utf8";

use lib '/usr/share/movabletype/extlib';

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 $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->()) {
    print join(':', map defined $obj->column($_) ? $obj->column($_) : '', @$cols), "\n";
}