Permalink
Browse files

Fix support for OPML generation (make it _really_ optional).

  • Loading branch information...
1 parent 660d44c commit 43df4cafa02a35f9a943c7516988f8b8513ff7dd @davorg committed Feb 22, 2011
Showing with 11 additions and 7 deletions.
  1. +10 −6 lib/Perlanet/Trait/OPML.pm
  2. +1 −1 t/01_basic.t
View
@@ -2,7 +2,7 @@ package Perlanet::Trait::OPML;
use Moose::Role;
use namespace::autoclean;
-use Carp qw( croak );
+use Carp qw( carp );
use POSIX qw(setlocale LC_ALL);
=head1 NAME
@@ -31,8 +31,9 @@ An L<XML::OPML::SimpleGen> object to generate the XML for the OPML file
has 'opml_generator' => (
is => 'rw',
- isa => 'XML::OPML::SimpleGen',
- lazy_build => 1
+ isa => 'Maybe[XML::OPML::SimpleGen]',
+ lazy_build => 1,
+ predicate => 'has_opml'
);
sub _build_opml_generator {
@@ -41,8 +42,10 @@ sub _build_opml_generator {
eval { require XML::OPML::SimpleGen; };
if ($@) {
- croak 'You need to install XML::OPML::SimpleGen to enable OPML ' .
+ carp 'You need to install XML::OPML::SimpleGen to enable OPML ' .
'support';
+ $self->opml(undef);
+ return;
}
my $loc = setlocale(LC_ALL, 'C');
@@ -63,9 +66,8 @@ Where to save the OPML feed when it has been created
=cut
has 'opml' => (
- isa => 'Str',
+ isa => 'Maybe[Str]',
is => 'rw',
- predicate => 'has_opml'
);
=head1 METHODS
@@ -81,6 +83,8 @@ each author into the OPML file and saves it to disk.
sub update_opml {
my ($self, @feeds) = @_;
+ return unless $self->has_opml;
+
foreach my $f (@feeds) {
$self->opml_generator->insert_outline(
title => $f->title,
View
@@ -24,7 +24,7 @@ $p->run;
ok(-e $p->feed->{file}, 'Feed created');
ok(-e $p->page->{file}, 'Page created');
SKIP: {
- skip 'XML::OPML::SimpleGen not installed', 1 unless $p->opml;
+ skip 'XML::OPML::SimpleGen not installed', 1 unless $p->has_opml;
ok(-e $p->opml, 'OPML created');
}

0 comments on commit 43df4ca

Please sign in to comment.