jkondo's Journal http://use.perl.org/~jkondo/journal/ jkondo's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:44:19+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 jkondo's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~jkondo/journal/ Moved to VOX http://use.perl.org/~jkondo/journal/32849?from=rss <p>I've moved this journal to VOX.com. See you at<br>http://jkondo.vox.com/</p> jkondo 2007-03-30T21:14:39+00:00 journal DBIx::MoCo 0.07 released http://use.perl.org/~jkondo/journal/32637?from=rss <tt>I uploaded DBIx::MoCo 0.07 today.<br><br>Changes from 0.06 are as follows.<br><br>0.07&nbsp; Fri Mar 9 2007<br>&nbsp; &nbsp; - Added DBIx::MoCo::Schema for schema definition<br>&nbsp; &nbsp; - Added count method to DBIx::MoCo<br>&nbsp; &nbsp; - Removed keys method and added unique_keys method to MoCo<br>&nbsp; &nbsp; - Changed primary_keys, unique_keys to get info automatically<br>&nbsp; &nbsp; &nbsp; &nbsp; - Added cache_status method to DBIx::MoCo<br>&nbsp; &nbsp; - Added DBIx::MoCo::Column and URI plugin for inflating columns<br>&nbsp; &nbsp; - Added DBIx::MoCo::Join for joined classes<br>&nbsp; &nbsp; - Added DBIx::MoCo::Readonly for read only classes.<br>&nbsp; &nbsp; - Fixed problem new session will start when save_changed is called.<br>&nbsp; &nbsp; - Added retrieve_by_a_or_b handler into DBIx::MoCo<br>&nbsp; &nbsp; - Added descriptions to MoCo's pod.<br>&nbsp; &nbsp; - Added retrieve_keys to MoCo<br><br>Enjoy!</tt> jkondo 2007-03-09T23:30:08+00:00 cpan Text::Hatena 0.20 released. http://use.perl.org/~jkondo/journal/32524?from=rss <tt>I uploaded Text::Hatena 0.20. It's quite new version of Text::Hatena.<br><br>I rewrote the whole code using Parse::RecDescent and Regexp::Assemble. Number of modules were reduced to 2 from 47 files. Line of codes where changed from 2600 lines to 600 lines. My benchmark marked 300-400% higher performance than ver.0.16.<br><br>I also removed some syntaxes which were specific to Hatena Diary.<br><br>Now, API for parsing text were changed too. Please be careful to upgrade your<br>Text::Hatena to version 0.20+.<br><br>You can use Text::Hatena simply as below.<br><br>my $html = Text::Hatena-&gt;parse($text);<br><br>And, you can extend your parser like this. You can easily make your original parser which can handle some other format.<br><br>package MyParser;<br>use strict;<br>use warnings;<br>use base qw(Text::Hatena);<br><br>__PACKAGE__-&gt;syntax(q|<br>&nbsp; &nbsp; h3 : "\n*" timestamp(?) inline(s)<br>&nbsp; &nbsp; timestamp :<nobr> <wbr></nobr>/\d{9,10}/ '*'<br>|);<br><br>sub h3 {<br>&nbsp; &nbsp; my $class = shift;<br>&nbsp; &nbsp; my $items = shift-&gt;{items};<br>&nbsp; &nbsp; my $title = $class-&gt;expand($items-&gt;[2]);<br>&nbsp; &nbsp; return if $title =~<nobr> <wbr></nobr>/^\*/;<br>&nbsp; &nbsp; my $ret = "&lt;h3&gt;$title";<br>&nbsp; &nbsp; if (my $time = $items-&gt;[1]-&gt;[0]) {<br>&nbsp; &nbsp; &nbsp; &nbsp; $ret<nobr> <wbr></nobr>.= qq|&lt;span class="timestamp"&gt;$time&lt;/span&gt;|;<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; $ret<nobr> <wbr></nobr>.= "&lt;/h3&gt;\n";<br>}<br><br>sub timestamp {<br>&nbsp; &nbsp; my $class = shift;<br>&nbsp; &nbsp; my $items = shift-&gt;{items};<br>&nbsp; &nbsp; return $items-&gt;[0];<br>}<br><br>1;<br><br>You can also extend inline elements like this.<br><br>Text::Hatena::AutoLink-&gt;syntax({<br>&nbsp; &nbsp; 'id:([\w-]+)' =&gt; sub {<br>&nbsp; &nbsp; &nbsp; &nbsp; my $mvar = shift;<br>&nbsp; &nbsp; &nbsp; &nbsp; my $name = $mvar-&gt;[1];<br>&nbsp; &nbsp; &nbsp; &nbsp; return qq|&lt;a href="/$name/"&gt;id:$name&lt;/a&gt;|;<br>&nbsp; &nbsp; },<br>&nbsp; &nbsp; 'd:id:([\w-]+)' =&gt; sub {<br>&nbsp; &nbsp; &nbsp; &nbsp; my $mvar = shift;<br>&nbsp; &nbsp; &nbsp; &nbsp; my $name = $mvar-&gt;[1];<br>&nbsp; &nbsp; &nbsp; &nbsp; return qq|&lt;a href="http://d.hatena.ne.jp/$name/"&gt;d:id:$name&lt;/a&gt;|;<br>&nbsp; &nbsp; },<br>});<br><br>I'd like to get your feedback.</tt> jkondo 2007-02-27T21:58:42+00:00 cpan I changed the name of my model class to DBIx::MoCo again. http://use.perl.org/~jkondo/journal/32380?from=rss <tt>I changed the name of my model class to DBIx::MoCo again. I uploaded DBIx::MoCo ver. 0.06 and removed MoCo* files just now.<br>Thanks for suggesting me to change the name.<br><br>I also implemented cache_connection attribute in DBIx::MoCo::DataBase.<br><br>If its set to 0, DBIx::MoCo::DataBase uses DBI-&gt;connect instead of<br>DBI-&gt;connect_cached.<br><br>&nbsp; DBIx::MoCo::DataBase-&gt;cache_connection(0);<br></tt> jkondo 2007-02-12T20:17:33+00:00 cpan I fixed bug in MoCo and added keys accessor. http://use.perl.org/~jkondo/journal/32316?from=rss <p>I uploaded MoCo ver 0.05 today.<br>I fixed a bug that cached objects are not flushed correctly when they're stored without primary keys.<br>I added keys accessor to MoCo and changed flush mechanism.</p><p>If you define Entry.pm like this,</p><p>package Entry;<br>__PACKAGE__-&gt;primary_keys(['entry_id']);<br>__PACKAGE__-&gt;keys(['uri']);</p><p>and, retrieve an entry from uri,</p><p>my $e = Entry-&gt;retrieve_by_uri('http://123');</p><p>and, create a new entry.</p><p>my $e2 = Entry-&gt;create(uri =&gt; 'http://123');</p><p>The first cache, $e is flushed correctly.</p><p>(I'm still considering about the name.)</p> jkondo 2007-02-04T01:31:45+00:00 cpan I changed the name to MoCo and released ver 0.04. http://use.perl.org/~jkondo/journal/32290?from=rss <p>I changed the name of my model class to MoCo.pm<br>It's light &amp; fast Model Component.<br>http://search.cpan.org/dist/MoCo/ (it's processing now)</p><p>Also, I implemented session features today.<br>You can delay your update/create operation using MoCo's session.</p><p>If you call MoCo-&gt;start_session once, a session will be started and update/create queries will be delayed until the session will be ended or save method will be called expressly.</p><p># in your web server etc..<br>MoCo-&gt;start_session;</p><p># in your scripts<br>my $user = Blog::User-&gt;retrieve(123);<br>$user-&gt;name('jkondo'); # not saved now. changed in cache.<br>print $user-&gt;name; # 'jkondo'<br>$user-&gt;save; # update db<br>print Blog::User-&gt;retrieve(123)-&gt;name; # 'jkondo'</p><p># Or, update queries will be thrown automatically after ending session.<br>$user-&gt;name('jkontan');<br>Moco-&gt;end_session;<br>print Blog::User-&gt;retrieve(123)-&gt;name; # 'jkontan'</p> jkondo 2007-01-31T21:00:22+00:00 cpan Class::Moco http://use.perl.org/~jkondo/journal/32283?from=rss <p>I uploaded Class::Moco 0.03 today.</p><p>Class::Moco is easy to cache model component.<br>It provides the way to create models like Class::DBI and store objects in cache easily.<br>http://search.cpan.org/dist/Class-Moco/</p><p>I'd like to get feedbacks.</p><p>Here is the SYNOPSIS of Class::Moco.</p><p> &nbsp; &nbsp; # First, set up your db.<br> &nbsp; &nbsp; package Blog::DataBase;<br> &nbsp; &nbsp; use base qw(Class::Moco::DataBase);</p><p> &nbsp; &nbsp; __PACKAGE__-&gt;dsn('dbi:mysql:dbname=blog');<br> &nbsp; &nbsp; __PACKAGE__-&gt;username('test');<br> &nbsp; &nbsp; __PACKAGE__-&gt;password('test');</p><p> &nbsp; &nbsp; 1;</p><p> &nbsp; &nbsp; # Second, create a base class for all models.<br> &nbsp; &nbsp; package Blog::TableObject;<br> &nbsp; &nbsp; use base qw 'Class::Moco'; # Inherit Class::Moco</p><p> &nbsp; &nbsp; __PACKAGE__-&gt;db_object('Blog::DataBase');</p><p> &nbsp; &nbsp; 1;</p><p> &nbsp; &nbsp; # Third, create your models.<br> &nbsp; &nbsp; package Blog::User;<br> &nbsp; &nbsp; use base qw 'Blog::TableObject';</p><p> &nbsp; &nbsp; __PACKAGE__-&gt;table('user');<br> &nbsp; &nbsp; __PACKAGE__-&gt;primary_keys(['user_id']);<br> &nbsp; &nbsp; __PACKAGE__-&gt;has_many(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entries =&gt; 'Blog::Entry',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { key =&gt; 'user_id' }<br> &nbsp; &nbsp; );<br> &nbsp; &nbsp; __PACKAGE__-&gt;has_many(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bookmarks =&gt; 'Blog::Bookmark',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { key =&gt; 'user_id' }<br> &nbsp; &nbsp; );</p><p> &nbsp; &nbsp; 1;</p><p> &nbsp; &nbsp; package Blog::Entry;<br> &nbsp; &nbsp; use base qw 'Blog::TableObject';</p><p> &nbsp; &nbsp; __PACKAGE__-&gt;table('entry');<br> &nbsp; &nbsp; __PACKAGE__-&gt;primary_keys(['entry_id']);<br> &nbsp; &nbsp; __PACKAGE__-&gt;has_a(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user =&gt; 'Blog::User',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { key =&gt; 'user_id' }<br> &nbsp; &nbsp; );<br> &nbsp; &nbsp; __PACKAGE__-&gt;has_many(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bookmarks =&gt; 'Blog::Bookmark',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { key =&gt; 'entry_id' }<br> &nbsp; &nbsp; );</p><p> &nbsp; &nbsp; 1;</p><p> &nbsp; &nbsp; package Blog::Bookmark;<br> &nbsp; &nbsp; use base qw 'Blog::TableObject';</p><p> &nbsp; &nbsp; __PACKAGE__-&gt;table('bookmark');<br> &nbsp; &nbsp; __PACKAGE__-&gt;primary_keys(['user_id','entry_id']);<br> &nbsp; &nbsp; __PACKAGE__-&gt;has_a(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user =&gt; 'Blog::User',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { key =&gt; 'user_id' }<br> &nbsp; &nbsp; );<br> &nbsp; &nbsp; __PACKAGE__-&gt;has_a(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entry =&gt; 'Blog::Entry',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { key =&gt; 'entry_id' }<br> &nbsp; &nbsp; );</p><p> &nbsp; &nbsp; 1;</p><p> &nbsp; &nbsp; # Now, You can use some methods same as in Class::DBI.<br> &nbsp; &nbsp; # And, all objects are stored in cache automatically.<br> &nbsp; &nbsp; my $user = Blog::User-&gt;retrieve(user_id =&gt; 123);<br> &nbsp; &nbsp; print $user-&gt;name;<br> &nbsp; &nbsp; $user-&gt;name('jkontan'); # update db immediately<br> &nbsp; &nbsp; print $user-&gt;name; # jkontan</p><p> &nbsp; &nbsp; my $user2 = Blog::User-&gt;retrieve(user_id =&gt; 123);<br> &nbsp; &nbsp; # $user is same as $user2!</p><p> &nbsp; &nbsp; # You can easily get has_many objects array.<br> &nbsp; &nbsp; my $entries = $user-&gt;entries;<br> &nbsp; &nbsp; my $entries2 = $user-&gt;entries;<br> &nbsp; &nbsp; # $entries is same reference as $entries2!<br> &nbsp; &nbsp; my $entry = $entries-&gt;first; # isa Blog::Entry<br> &nbsp; &nbsp; print $entry-&gt;title; # you can use methods in Entry class.</p><p> &nbsp; &nbsp; Blog::Entry-&gt;create(<br> &nbsp; &nbsp; &nbsp; &nbsp; user_id =&gt; 123,<br> &nbsp; &nbsp; &nbsp; &nbsp; title =&gt; 'new entry!',<br> &nbsp; &nbsp; );<br> &nbsp; &nbsp; # $user-&gt;entries will be flushed automatically.<br> &nbsp; &nbsp; my $entries3 = $user-&gt;entries;<br> &nbsp; &nbsp; # $entries3 isnt $entries!</p><p> &nbsp; &nbsp; print ($posts1-&gt;[-1] eq $posts2-&gt;[-1]); # 1<br> &nbsp; &nbsp; print ($posts1-&gt;[-1] eq $posts3-&gt;[-1]); # 1<br> &nbsp; &nbsp; # It's same instance!</p> jkondo 2007-01-30T22:33:19+00:00 cpan Hello Perl http://use.perl.org/~jkondo/journal/32278?from=rss It's my first journal. jkondo 2007-01-30T05:32:53+00:00 journal