Changeset 32595
- Timestamp:
- 04/19/09 00:05:21 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Morris/trunk/lib/Morris/CLI/LogUpload.pm
r32566 r32595 2 2 use utf8; 3 3 use Moose; 4 use Moose::Util::TypeConstraints; 4 5 use MooseX::AttributeHelpers; 5 use MooseX::Types::DateTime;6 6 use MooseX::Types::URI; 7 use Config::Any; 7 8 use DateTime; 9 use DateTime::Format::Strptime; 8 10 use DBI; 11 use Encode qw(encode_utf8); 9 12 use File::Temp; 10 13 use Template; 14 use Template::Stash::ForceUTF8; 11 15 use WWW::Mechanize; 12 16 … … 23 27 ); 24 28 29 subtype 'Morris::CLI::ValueList' 30 => as 'ArrayRef' 31 ; 32 coerce 'Morris::CLI::ValueList' 33 => from 'Str' 34 => via { [ $_ ] } 35 ; 25 36 has connect_info => ( 26 37 is => 'rw', 27 isa => ' ArrayRef',38 isa => 'Morris::CLI::ValueList', 28 39 required => 1, 40 coerce => 1, 29 41 auto_deref => 1, 30 42 ); … … 33 45 metaclass => 'Collection::Array', 34 46 is => 'ro', 35 isa => ' ArrayRef[Str]',36 default => sub { +[] },47 isa => 'Morris::CLI::ValueList', 48 coerce => 1, 37 49 required => 1, 38 50 provides => { … … 44 56 is => 'rw', 45 57 isa => 'Str', 46 coerce => 1, 58 required => 1, 59 ); 60 61 has target => ( 62 is => 'rw', 63 isa => 'Str', 64 trigger => sub { 65 my $date = DateTime::Format::Strptime->new( 66 pattern => '%Y-%m-%d', 67 time_zone => 'Asia/Tokyo' 68 )->parse_datetime($_[1] ); 69 $date->set(hour => 6); 70 $_[0]->date( $date ) 71 } 47 72 ); 48 73 49 74 has date => ( 50 is => 'r o',75 is => 'rw', 51 76 isa => 'DateTime', 52 coerce => 1,53 77 default => sub { 54 78 DateTime->now(time_zone => 'Asia/Tokyo') … … 113 137 sub _build_dbh { 114 138 my $self = shift; 139 $self->{connect_info}->[3] = { RaiseError => 1, AutoCommit => 1 }; 115 140 DBI->connect($self->connect_info); 116 141 } … … 119 144 my ($self, $channel) = @_; 120 145 121 my $start = $self->date ;122 123 my $dbh = DBI->connect();146 my $start = $self->date->clone; 147 148 my $dbh = $self->dbh; 124 149 125 150 my $sth = $dbh->prepare("SELECT * FROM log WHERE channel = ? AND created_on >= ? AND created_on <= ?"); 126 $sth->execute($channel, $start->epoch, $start->clone->add(day => 1)->epoch);151 $sth->execute($channel, $start->epoch, $start->clone->add(days => 1)->epoch); 127 152 128 153 my @messages; 129 while (my $h ,$sth->fetchrow_hashref) {154 while (my $h = $sth->fetchrow_hashref) { 130 155 push @messages, $h; 156 $h->{message} =~ s/\|/\\|/g; 157 $h->{message} =~ s{((?:(?:https?):)(?://(?:[^\s/?#]*))(?:[^\s?#]*)(?:\?(?:[^\s#]*))?(?:#(?:.*))?)}{"$1":$1}g; 131 158 $h->{created_on} = DateTime->from_epoch(epoch => $h->{created_on}, time_zone => 'Asia/Tokyo'); 132 159 } 133 134 my $tt = Template->new(); 160 $sth->finish; 161 $dbh->disconnect; 162 163 return if !@messages; 164 165 my $tt = Template->new( 166 STASH => Template::Stash::ForceUTF8->new 167 ); 135 168 my %vars = ( 136 169 channel => $channel, … … 141 174 $tt->process(\*DATA, \%vars, \$output) or 142 175 die $tt->error; 143 176 $output = encode_utf8($output); 177 warn $output; 144 178 my $ua = WWW::Mechanize->new(); 145 179 if ($self->basic_auth_username && $self->basic_auth_password ) { … … 157 191 158 192 $ua->get($self->make_url( "/Log/" . $start->strftime('%Y-%m-%d') . ".edit" )); 193 159 194 $ua->submit_form( 160 195 form_number => 2,
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)