Skip to content

Commit

Permalink
Renamed the module to the more correct designation of Blog::Manager.
Browse files Browse the repository at this point in the history
Turned the Manager into a factory that creates specific managers by type.
Created a generic Blog Manager.
Created the Tumblr manager, defined a few of its properties.
  • Loading branch information
smpb committed Feb 28, 2011
1 parent 5143395 commit 32317c7
Show file tree
Hide file tree
Showing 13 changed files with 460 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .includepath
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<includepath>
<includepathentry path="/Users/smpb/Developer/libs/lib/perl5" />
</includepath>

2 changes: 1 addition & 1 deletion .project
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Blog-Manage</name>
<name>Blog-Manager</name>
<comment></comment>
<projects>
</projects>
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST
Expand Up @@ -2,7 +2,7 @@ Changes
MANIFEST
Makefile.PL
README
lib/Blog/Manage.pm
lib/Blog/Manager.pm
t/00-load.t
t/manifest.t
t/pod-coverage.t
Expand Down
8 changes: 4 additions & 4 deletions Makefile.PL
Expand Up @@ -3,10 +3,10 @@ use warnings;
use ExtUtils::MakeMaker;

WriteMakefile(
NAME => 'Blog::Manage',
NAME => 'Blog::Manager',
AUTHOR => q{"Sérgio Bernardino" <"me@sergiobernardino.net">},
VERSION_FROM => 'lib/Blog/Manage.pm',
ABSTRACT_FROM => 'lib/Blog/Manage.pm',
VERSION_FROM => 'lib/Blog/Manager.pm',
ABSTRACT_FROM => 'lib/Blog/Manager.pm',
($ExtUtils::MakeMaker::VERSION >= 6.3002
? ('LICENSE'=> 'perl')
: ()),
Expand All @@ -15,5 +15,5 @@ WriteMakefile(
'Test::More' => 0,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Blog-Manage-*' },
clean => { FILES => 'Blog-Manager-*' },
);
12 changes: 6 additions & 6 deletions README
@@ -1,4 +1,4 @@
Blog-Manage
Blog-Manager

The README is used to introduce the module and provide instructions on
how to install the module, any machine dependencies it may have (for
Expand Down Expand Up @@ -26,21 +26,21 @@ SUPPORT AND DOCUMENTATION
After installing, you can find documentation for this module with the
perldoc command.

perldoc Blog::Manage
perldoc Blog::Manager

You can also look for information at:

RT, CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Blog-Manage
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Blog-Manager

AnnoCPAN, Annotated CPAN documentation
http://annocpan.org/dist/Blog-Manage
http://annocpan.org/dist/Blog-Manager

CPAN Ratings
http://cpanratings.perl.org/d/Blog-Manage
http://cpanratings.perl.org/d/Blog-Manager

Search CPAN
http://search.cpan.org/dist/Blog-Manage/
http://search.cpan.org/dist/Blog-Manager/


LICENSE AND COPYRIGHT
Expand Down
2 changes: 1 addition & 1 deletion ignore.txt
Expand Up @@ -9,4 +9,4 @@ pm_to_blib*
.lwpcookies
cover_db
pod2htm*.tmp
Blog-Manage-*
Blog-Manager-*
202 changes: 202 additions & 0 deletions lib/Blog/Manager.pm
@@ -0,0 +1,202 @@
package Blog::Manager;

use warnings;
use strict;
use Blog::Manager::Platform;
use Module::Pluggable require => 1, search_path => ['Blog::Manager'], except => 'Blog::Manager::Platform';
use Log::Handler;
use Data::Dumper;

=head1 NAME
Blog::Manager - The great new Blog::Manager!
=head1 VERSION
Version 0.01
=cut

our $VERSION = '0.01';


=head1 SYNOPSIS
Quick summary of what the module does.
Perhaps a little code snippet.
use Blog::Manager;
my $foo = Blog::Manager->new();
...
=head1 EXPORT
A list of functions that can be exported. You can delete this section
if you don't export anything, such as for a purely object-oriented module.
=head1 SUBROUTINES/METHODS
=head2 new
=cut

sub new
{
my $class = shift;
return $class if (ref $class );

my $self = {};
my $options = {
log_to => 'STDERR',
maxlevel => 'debug',
minlevel => 'error',
timeformat => "%d/%m/%Y %H:%M:%S",
};
$self->{'_LOG'} = Log::Handler->create_logger('Blog::Manager');
$self->{'_LOG'}->add(screen => $options); # default LOG

bless($self, $class);

# argument processing
if (@_ % 2 == 0)
{
# upper-case (only) the hash keys
my %args = @_;
%args = map { uc $_ => $args{$_} } keys %args;

$self->{'_LOG'}->debug("$class - A new manager factory was requested.");

if (defined $args{'LOGFILE'})
{
delete($options->{'log_to'}); # we don't want this anymore
$options->{'filename'} = $args{'LOG_FILE'};
$self->{'_LOG'}->reload; # remove the 'screen LOG'
$self->{'_LOG'}->add(file => $options);
delete($args{'LOG_FILE'}); # we don't need this anymore
}
}
else
{
$self->{'_LOG'}->error("$class - Invalid arguments list for instantiation.");
return;
}

#

return $self;
}

=head2 new
=cut

sub get_manager
{
my $self = shift;
unless (ref $self ) { $self = Blog::Manager->new; }

# argument processing
if (@_ % 2 == 0)
{
# upper-case (only) the hash keys
my %args = @_;
%args = map { uc $_ => $args{$_} } keys %args;

unless (defined $args{'TYPE'})
{
$self->{'_LOG'}->error("$self - Can't continue. No type of blog platform defined.");
return;
}

$self->{'_LOG'}->debug("$self - A new manager was requested with these args: " . Dumper(\%args));

# cycle plugins in search of the right one
foreach my $plugin ($self->plugins)
{
$args{'TYPE'} = uc($args{'TYPE'});
if (uc($plugin) =~ m/$args{'TYPE'}$/)
{
delete($args{'TYPE'}); # I don't want this as an argument passed to the plugin
$self->{'_LOG'}->debug("$self - Found the correct plugin. It's $plugin.");
if (my $manager = $plugin->new(%args))
{
$self->{'_LOG'}->debug("$self - We have an instance of the plugin: " . Dumper($manager));
return $manager;
}
else
{
$self->{'_LOG'}->error("$self - Unable to create an instance for the manager.");
return $manager;
}
}
}
}
else
{
$self->{'_LOG'}->error("$self - Invalid arguments list for instantiation.");
return;
}
}

=head1 AUTHOR
"Sergio Bernardino", C<< <"me at sergiobernardino.net"> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-blog-manage at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Blog-Manage>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Blog::Manager
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Blog-Manage>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Blog-Manage>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/Blog-Manage>
=item * Search CPAN
L<http://search.cpan.org/dist/Blog-Manage/>
=back
=head1 ACKNOWLEDGEMENTS
=head1 LICENSE AND COPYRIGHT
Copyright 2011 "Sergio Bernardino".
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut

1; # End of Blog::Manager

0 comments on commit 32317c7

Please sign in to comment.