Plaggerå®è¡ä¸ã«configã対話çã«å ¥åãããã©ã°ã¤ã³
ãã¹ã¯ã¼ããå¿ è¦ãªãã©ã°ã¤ã³ã使ãå ´åãconfig.yamlã«ãã¹ã¯ã¼ããç´æ¥æ¸ããããããããªã®ã§ããã対話çã«å ¥åãããããªãã¨æã£ã¦å®è¡ä¸ã«ãã©ã¡ã¼ã¿ãå ¥åã§ãããã©ã°ã¤ã³ãä½ã£ã¦ã¿ã¾ãããï¼æ¢ã«ãã£ããæ²ããï¼
使ãæ¹
ä¾ãã°CustomFeed::Mixiã®å ´åã
plugins: - module: CustomFeed::Mixi config: email: [email protected] password: password fetch_body: 1 show_icon: 1 feed_type: - RecentComment - FriendDiary - Message - module: Publish::Debug
ã®ããã«æ¸ãã¾ããã以ä¸ã®ããã«ãããã¨ã§config.yamlãæ¸ãæããã«å®è¡æã«emailã¨passwordãå ¥åããããã¨ãã§ãã¾ãã
plugins: - module: CustomConfig config: - ReadLine: prompt: "What is your Mixi's email? [[email protected]] " name: email - ReadPassword: prompt: "What is your Mixi's password? [password] " name: password - module: CustomFeed::Mixi config: email: [email protected] password: password fetch_body: 1 show_icon: 1 feed_type: - RecentComment - FriendDiary - Message - module: Publish::Debug
CustomConfigå
ã®configã§æå®ããããã©ã°ã¤ã³ãä¸ããé ã«å¦çããã¾ããReadLineã§ã¯ä¸æåæ¢ãä¸è¡å
¥åå¾
ã¡ã¨ãªãã¾ããããã§å
¥åããå¤ã次ã®moduleï¼ä¸ã®ä¾ã§ã¯CustomFeed::Mixiï¼ã®configã«ä¸æ¸ãããã¾ããä½ãå
¥åããªããã°ä¸æ¸ããã¾ããï¼CustomFeed::Mixiã§ã®å¤ãããã©ã«ãå¤ã¨ãªãã¾ãï¼ãpromptãæå®ããã¦ããå ´åããã®æååã¯å
¥åå¾
ã¡ã«å
¥ãç´åã«æ¨æºã¨ã©ã¼åºåã«å°åããã¾ãã
ReadPasswordã¯ReadLineã®ã¨ã³ã¼ããã¯ç¡ãçã§ãã
æ°ã«ãªããã¨
- æ¢ã«åããããªã¢ã¸ã¥ã¼ã«ãããããç¥ãã¾ããï¼è´å½çï¼ã
- åPluginã®confã¯ç¬ç«ãã¦ããããã$context->{plugins}ãå¼ã£å¼µã£ã¦ãã¦å¤ãªãã¨ããã¦ãã¾ãã
- é©åãªã«ãã´ãªãè¦ã¤ãããªãã£ããããPlagger::Pluginã«CustomConfigãæã£ã¦ã¾ãã
- CustomConfigã®configããpassword: ReadPasswordãã¿ãããªæãã«ãããã£ãã®ã§ãããè¨å®ãã¼ã"password"ãå«ãã§ããã¨ãPlagger::Plugin#do_walk,Plagger#rewrite_configã«ãã£ã¦æ¸ãæãããã¦ãã¾ããããå°ãç´æçã§ã¯ãªãè¨å®æ¹æ³ã«ãã¦ãã¾ãã
- ãã¹ããæ¸ãã¦ãã¾ããã
ãã¦ã³ãã¼ã
http://rcl.hp.infoseek.co.jp/pub/Plagger-Plugin-CustomConfig-0.01.tar.gz
ã½ã¼ã¹ï¼*.pmã®ã¿æç²ï¼
Plagger/Plugin/CustomConfig.pm
package Plagger::Plugin::CustomConfig; use strict; use warnings; use version; our $VERSION = qv( (qw$Revision: 190 $)[1] / 1000 ); use Carp; use English qw(-no_match_vars); use UNIVERSAL::require; use base qw(Plagger::Plugin); sub register { my ( $self, $context ) = @_; $context->register_hook( $self, 'plugin.init' => \&init ); return; } sub init { my ( $self, $context ) = @_; foreach my $i ( 0 .. @{ $context->{plugins} } ) { if ( ref $context->{plugins}->[$i] ne __PACKAGE__ ) { next; } $i++; my $plugin = $context->{plugins}->[$i]; # $plugin is the next plugin. foreach my $ref ( @{ $self->conf } ) { my $module = __PACKAGE__ . q{::} . ( keys %{$ref} )[0]; my $config = ( values %{$ref} )[0]; $module->require or croak $EVAL_ERROR; my $value = $module->run($config); if ( defined $value ) { $plugin->conf->{ $config->{name} } = $value; } } } return; } 1;
Plagger/Plugin/CustomConfig/ReadLine.pm
package Plagger::Plugin::CustomConfig::ReadLine; use strict; use warnings; use version; our $VERSION = qv( (qw$Revision: 190 $)[1] / 1000 ); use English qw(-no_match_vars); use Term::ReadKey; sub run { my ( $class, $config ) = @_; if ( exists $config->{prompt} ) { print {*STDERR} $config->{prompt}; } my $value; eval { $value = ReadLine(0); chomp $value; }; if ($EVAL_ERROR) { return; } return $value; } 1;
Plagger/Plugin/CustomConfig/ReadPassword.pm
package Plagger::Plugin::CustomConfig::ReadPassword; use strict; use warnings; use version; our $VERSION = qv( (qw$Revision: 190 $)[1] / 1000 ); use English qw(-no_match_vars); use Term::ReadKey; sub run { my ( $class, $config ) = @_; if ( exists $config->{prompt} ) { print {*STDERR} $config->{prompt}; } my $value; eval { ReadMode('noecho'); $value = ReadLine(0); chomp $value; }; ReadMode(0); if ($EVAL_ERROR) { return; } return $value; } 1;