--- /dev/null
+#!/usr/bin/perl
+## ----------------------------------------------------------------------------
+
+use strict;
+use warnings;
+use Data::Dumper;
+use CIL::Issue;
+use Term::CallEditor;
+
+my $COMMANDS = {
+ add => 1,
+ show => 1,
+ comment => 1,
+ update => 1
+};
+
+## ----------------------------------------------------------------------------
+
+{
+ my ($command) = shift;
+ unless ( defined $command and exists $COMMANDS->{$command} ) {
+ usage();
+ exit 2;
+ }
+
+ if ( $command eq 'show' ) {
+ my ($issue_name) = @ARGV;
+ show($issue_name);
+
+ }
+ elsif ( $command eq 'add' ) {
+ add();
+ }
+
+}
+
+sub show {
+ my ($issue_name) = @_;
+
+ # firstly, read the issue in
+ my $issue = CIL::Issue->load_issue('2008-04-17T22:05:02.000Z');
+
+ unless ( defined $issue ) {
+ print STDERR "Couldn't load issue '$issue'\n";
+ return;
+ }
+
+ separator();
+ title('Details');
+ field( 'Summary', $issue->Summary() );
+ field( 'Name', $issue->Name() );
+ field( 'CreatedBy', $issue->CreatedBy() );
+ field( 'Inserted', $issue->Inserted() );
+ field( 'Status', $issue->Status() );
+ field( 'Labels', $issue->Labels() );
+ separator();
+ text('Description', $issue->Description());
+ separator();
+ title('Comments');
+ separator();
+}
+
+sub add {
+ my ($issue_name) = @_;
+ my $fh = solicit('FOO: please replace this text');
+ die "$Term::CallEditor::errstr\n" unless $fh;
+ my $text;
+ $text .= $_ while <$fh>;
+ separator();
+ text('You said:', $text);
+ separator();
+}
+
+## ----------------------------------------------------------------------------
+
+sub usage {
+ print <<"END_USAGE";
+Usage: $0 <command> [options]
+
+Commands:
+ add
+ show <issue>
+ comment <issue>
+ update <issue>
+
+See <http://github.com/andychilton/cil/> for further information.
+Report bugs to <andychilton -at- gmail -dot- com>.
+END_USAGE
+}
+
+sub say {
+ print $_[0], "\n";
+}
+
+sub separator {
+ say('=' x 79);
+}
+
+sub title {
+ my ($title) = @_;
+ my $msg = "--- $title ";
+ $msg .= '-' x (74 - length($title));
+ say($msg);
+}
+
+sub field {
+ my ($field, $value) = @_;
+ my $msg = "$field";
+ $msg .= " " x (12 - length($field));
+ say("$msg: " . (defined $value ? $value : '') );
+}
+
+sub text {
+ my ($field, $value) = @_;
+ title($field);
+ say "";
+ say($value);
+ say "";
+}
+
+## ----------------------------------------------------------------------------
--- /dev/null
+## ----------------------------------------------------------------------------
+package CIL::Attachment;
+
+use strict;
+use warnings;
+
+use base qw(Class::Accessor);
+__PACKAGE__->mk_accessors(qw(filename));
+
+## ----------------------------------------------------------------------------
+1;
+## ----------------------------------------------------------------------------
--- /dev/null
+## ----------------------------------------------------------------------------
+package CIL::Base;
+
+use strict;
+use warnings;
+use DateTime;
+
+use base qw(Class::Accessor);
+__PACKAGE__->mk_accessors(qw(Description CreatedBy Inserted Updated));
+
+sub inserted {
+ my ($self) = @_;
+ $self->{Inserted} = DateTime->new()->iso8601;
+}
+
+sub updated {
+ my ($self) = @_;
+ $self->{Updated} = DateTime->new()->iso8601;
+}
+
+## ----------------------------------------------------------------------------
+1;
+## ----------------------------------------------------------------------------
--- /dev/null
+## ----------------------------------------------------------------------------
+package CIL::Comment;
+
+use strict;
+use warnings;
+use base qw(CIL::Base);
+
+## ----------------------------------------------------------------------------
+1;
+## ----------------------------------------------------------------------------
--- /dev/null
+## ----------------------------------------------------------------------------
+package CIL::Issue;
+
+use strict;
+use warnings;
+use Data::Dumper;
+use Config::IniFiles;
+
+use base qw(CIL::Base);
+__PACKAGE__->mk_accessors(qw(Name Summary Status Labels Comments));
+
+## ----------------------------------------------------------------------------
+
+sub load_issue {
+ my ($self, $name) = @_;
+ return unless defined $name;
+
+ my $filename = "issues/$name.ini";
+
+ return unless -f $filename;
+ my $issue = CIL::Issue->new();
+ $issue->read_issue( $filename );
+ $issue->Name( $name );
+ return $issue;
+}
+
+sub read_issue {
+ my ($self, $filename) = @_;
+
+ my $cfg = Config::IniFiles->new( -file => $filename );
+
+ foreach my $attr ( qw(Summary Description) ) {
+ $self->{$attr} = $cfg->val( 'Issue', $attr );
+ }
+}
+
+sub reset {
+ my ($self) = @_;
+
+ foreach my $attr ( qw(changed) ) {
+ delete $self->{$attr};
+ }
+}
+
+sub inserted {
+ my ($self) = @_;
+ $self->{data}{inserted} = time;
+}
+
+sub updated {
+ my ($self) = @_;
+ $self->{changed} = '1';
+ $self->{data}{updated} = time;
+}
+
+sub add_comment {
+ my ($self, $comment_h) = @_;
+
+ my $comment = CIL::Comment->new($comment_h);
+
+}
+
+## ----------------------------------------------------------------------------
+1;
+## ----------------------------------------------------------------------------