Changeset 225
- Timestamp:
- 03/01/06 22:57:12
- Files:
-
- trunk/plagger/lib/Plagger.pm (modified) (4 diffs)
- trunk/plagger/lib/Plagger/Cache.pm (added)
- trunk/plagger/lib/Plagger/CacheProxy.pm (added)
- trunk/plagger/lib/Plagger/Plugin.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger.pm
r194 r225 6 6 use Carp; 7 7 use Data::Dumper; 8 use File::Basename; 8 9 use File::Find::Rule; 9 10 use YAML; … … 11 12 12 13 use base qw( Class::Accessor::Fast ); 13 __PACKAGE__->mk_accessors( qw(conf update subscription plugins_path) ); 14 14 __PACKAGE__->mk_accessors( qw(conf update subscription plugins_path cache) ); 15 16 use Plagger::Cache; 17 use Plagger::CacheProxy; 15 18 use Plagger::Date; 16 19 use Plagger::Entry; … … 42 45 $config = YAML::LoadFile($opt{config}); 43 46 $self->{conf} = $config->{global}; 44 $self->{conf}->{log} ||= { level => 'debug' };47 $self->{conf}->{log} ||= { level => 'debug' }; 45 48 } else { 46 49 croak "Plagger->bootstrap: $opt{config}: $!"; 47 50 } 48 51 52 $self->load_cache($opt{config}); 53 49 54 local *Plagger::context = sub { $self }; 50 51 55 $self->load_plugins(@{ $config->{plugins} || [] }); 52 56 $self->run(); 57 } 58 59 sub load_cache { 60 my($self, $config) = @_; 61 62 # use config filename as a base directory for cache 63 my $base = ( basename($config) =~ /^(.*?)\.yaml$/ )[0]; 64 my $dir = $base eq 'config' ? ".plagger" : ".plagger-$base"; 65 66 $self->{conf}->{cache} ||= { 67 base => File::Spec->catfile($ENV{HOME}, $dir), 68 }; 69 70 $self->cache( Plagger::Cache->new($self->{conf}->{cache}) ); 53 71 } 54 72 … … 106 124 107 125 my $plugin = $module->new($config); 126 $plugin->cache( Plagger::CacheProxy->new($plugin, $self->cache) ); 108 127 $plugin->register($self); 109 128 } trunk/plagger/lib/Plagger/Plugin.pm
r103 r225 1 1 package Plagger::Plugin; 2 2 use strict; 3 use base qw( Class::Accessor::Fast ); 4 5 __PACKAGE__->mk_accessors( qw(conf rule rule_hook cache) ); 3 6 4 7 use Plagger::Rule; … … 32 35 sub rule { $_[0]->{rule} } 33 36 34 sub rule_hook {35 my $self = shift;36 $self->{rule_hook} = shift if @_;37 $self->{rule_hook};38 }39 40 37 sub dispatch_rule_on { 41 38 my($self, $hook) = @_; … … 43 40 } 44 41 42 sub class_id { 43 my $self = shift; 44 45 my $pkg = ref($self); 46 $pkg =~ s/Plagger::Plugin:://; 47 my @pkg = split /::/, $pkg; 48 49 return join '-', map lc, @pkg; 50 } 51 45 52 1;
