Skip to content

Commit

Permalink
Merge branch 'release/0.001'
Browse files Browse the repository at this point in the history
  • Loading branch information
keedi committed Dec 24, 2012
2 parents 47243a7 + 817b195 commit e352591
Show file tree
Hide file tree
Showing 12 changed files with 1,509 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .gitignore
@@ -0,0 +1,48 @@
MyTodo-*

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.apk

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store?
ehthumbs.db
Icon?
Thumbs.db

# Configuration files #
#######################
*.project
*.settings
*.classpath

# Editor generated files #
##########################
*.swp
*.bak
7 changes: 7 additions & 0 deletions Changes
@@ -0,0 +1,7 @@
Release history for MyTodo

0.001
- Add MyTodo main module
- Patch MooX::Options
- Add mytodo.pl utility
- Add mytodo-web.{pl|conf} web app
141 changes: 141 additions & 0 deletions bin/mytodo.pl
@@ -0,0 +1,141 @@
#!perl
# ABSTRACT: MyTodo command line utility
# PODNAME: mytodo.pl

use 5.010;
use utf8;
use strict;
use warnings;

use Encode qw( decode_utf8 encode_utf8 );
use Time::Piece;

use MyTodo;
use MyTodo::Script;
use MyTodo::Util;

binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';

my $opt = MyTodo::Script->new_with_options;

if ( $opt->schema_sqlite ) {
say for map { chomp; "$_;" } MyTodo::Util->sql_sqlite;
exit;
}

my %dbattrs = map { split /=/ } @{ $opt->dbattr };
my $todo = MyTodo->new(
dsn => $opt->dsn,
dbusername => $opt->dbusername,
dbpassword => $opt->dbpassword,
dbattr => \%dbattrs,
);

if ( $opt->list ) {
my $display_func = sub {
my $item = shift;

my $str = sprintf(
"[%-5s] %5s : #%-2d %s",
uc $item->status,
"\x{2605}" x $item->priority . "\x{2606}" x (5 - $item->priority),
# 2605(★), 2606(☆)
$item->id,
decode_utf8($item->content),
);
if ($item->deadline) {
my $deadline = Time::Seconds->new( $item->deadline - time )->pretty;
$deadline =~ s/minus /-/;
$deadline =~ s/(\d+) days, /sprintf('%2dD', $1)/e;
$deadline =~ s/(\d+) hours, /sprintf('%2dH', $1)/e;
$deadline =~ s/(\d+) minutes, /sprintf('%2dM', $1)/e;
$deadline =~ s/\d+ seconds$//;
$str .= " ($deadline)";
}
say $str;
};

for my $search (
{ status => 'doing' },
{ status => 'todo' },
{ status => 'done' },
)
{
my $rs = $todo->list(
search => [ $search ],
order_by => [ '-me.priority' ],
);
$display_func->($_) while $_ = $rs->next;
}
exit;
}

if ( $opt->add ) {
my $content = shift;
my $epoch = time;

my %params;
$params{content} = $content if $content;
$params{priority} = $opt->priority if $opt->priority;
$params{status} = $opt->status if $opt->status && $opt->status =~ /^(todo|doing|done)$/;
if ($opt->deadline) {
my $t = Time::Piece->strptime($opt->deadline, "%Y-%m-%dT%H:%M:%S");
$params{deadline} = $t->epoch;
}

$todo->add(%params);

exit;
}

if ( $opt->delete ) {
return unless $opt->delete;
$todo->delete( id => $opt->delete );
exit;
}

if ( $opt->edit ) {
my $content = shift;
my $epoch = time;

return unless $opt->edit;

my %params;
$params{id} = $opt->edit;
$params{content} = $content if $content;
$params{priority} = $opt->priority if $opt->priority;
$params{status} = $opt->status if $opt->status && $opt->status =~ /^(todo|doing|done)$/;
if ($opt->deadline) {
my $t = Time::Piece->strptime($opt->deadline, "%Y-%m-%dT%H:%M:%S");
$params{deadline} = $t->epoch;
}

$todo->edit(%params);
exit;
}

__END__
=head1 SYNOPSIS
$ mkdir ~/.mytodo
$ todo --schema_sqlite | sqlite3 ~/.mytodo/mytodo.db
$ todo -h
$ todo -a 'writing document for MyTodo'
$ todo -a 'writing perl example using LibreOffice SDK' -p3 -sdoing
$ todo -e1 -p5
$ todo -l
$ todo -d1 -d2
=head1 DESCRIPTION
...
=head1 SEE ALSO
=cut
32 changes: 32 additions & 0 deletions dist.ini
@@ -0,0 +1,32 @@
name = MyTodo
author = Keedi Kim - 김도형 <keedi@cpan.org>
license = Perl_5
copyright_holder = Keedi Kim
copyright_year = 2012
version = 0.001

;[@Basic]
[@Filter]
-bundle = @Basic
-remove = UploadToCPAN
[FakeRelease]

[MetaResources]
;homepage =
;bugtracker.web =
;repository.web = http://github.com/keedi/mytodo
;repository.url = http://github.com/keedi/mytodo.git
repository.type = git

[AutoPrereqs]
[PkgVersion]
[ReadmeMarkdownFromPod]
[InstallGuide]

[Prereqs / RuntimeRequires]

[PodCoverageTests]
[PodSyntaxTests]

[PodWeaver]
config_plugin = @KEEDI
158 changes: 158 additions & 0 deletions lib/MyTodo.pm
@@ -0,0 +1,158 @@
package MyTodo;
# ABSTRACT: Personal To-Do management

use Moo;
use MooX::Types::MooseLike::Base qw( Str HashRef Maybe );
use namespace::clean -except => 'meta';

use DBIx::Lite;
#use MyTodo::Patch::DBIx::Lite::ResultSet;

has dsn => (
is => 'ro',
isa => Str,
required => 1,
);

has dbusername => (
is => 'ro',
isa => Maybe[Str],
);

has dbpassword => (
is => 'ro',
isa => Maybe[Str],
);

has dbattr => (
is => 'ro',
isa => Maybe[HashRef],
);

has _dbix => (
is => 'lazy',
builder => '_builder_handle',
);

sub _builder_handle {
my $self = shift;

my $dbix = DBIx::Lite->connect(
$self->dsn,
$self->dbusername,
$self->dbpassword,
$self->dbattr,
);
$dbix->schema->table('mytodo')->autopk('id');

return $dbix;
}

sub BUILD {
my $self = shift;

$self->_dbix;
}

sub add {
my $self = shift;

my $epoch = time;
my %params = (
status => 'todo',
created_on => $epoch,
updated_on => $epoch,
@_,
);

my $todo = $self->_dbix->table('mytodo')->insert({ %params });

return $todo;
}

sub delete {
my ( $self, %params ) = @_;

my $id = delete $params{id};
return unless $id;

$self->_dbix->table('mytodo')
->search({ id => $id })
->delete;
}

sub edit {
my ( $self, %params ) = @_;

my $id = delete $params{id};
return unless $id;

$self->_dbix->table('mytodo')
->search({ id => $id })
->update({ %params, updated_on => time });
}

sub list {
my $self = shift;
my %params = @_;

my $rs
= $self->_dbix->table('mytodo')
->select(qw/
id
status
content
priority
deadline
created_on
updated_on
/);
$rs = $rs->search($_) for @{ $params{search} };
$rs = $rs->order_by($_) for @{ $params{order_by} };

return $rs;
}

1;
__END__
=head1 SYNOPSIS
use MyTodo;
my $todo = MyTodo->new(
dsn => 'dbi:mysql:mytodo',
dbusername => 'mytodo',
dbpassword => 'mytodo',
dbattr => +{
...
},
);
=head1 DESCRIPTION
...
=attr dsn
=attr dbusername
=attr dbpassword
=attr dbattr
=method add
=method delete
=method edit
=method list
=head1 SEE ALSO

0 comments on commit e352591

Please sign in to comment.