diff --git a/Changes b/Changes index c0ab4d0..a583012 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,5 @@ -# Change file for Plack::App::SeeAlso - {{$NEXT}} + Don't rely on accessor methods 0.11 2012-04-18 Fixed some typos and better error handling diff --git a/dist.ini b/dist.ini index 6b6a908..f4bd5a5 100644 --- a/dist.ini +++ b/dist.ini @@ -1,7 +1,7 @@ name = Plack-App-SeeAlso license = Perl_5 -version = 0.13 -copyright_year = 2013 +version = 0.14 +copyright_year = 2014 author = Jakob Voß copyright_holder = Jakob Voß @@ -22,9 +22,6 @@ match = ^.*\.psgi$ match = ^examples/* match = ^share/example* -; Be pedantic -; [Test::Perl::Critic] - ; Replace {{$NEXT}} in first line of Changes with version number and timestamp [NextRelease] format=%-9v %{yyyy-MM-dd}d diff --git a/lib/Plack/App/SeeAlso.pm b/lib/Plack/App/SeeAlso.pm index de77ae6..c88d75a 100644 --- a/lib/Plack/App/SeeAlso.pm +++ b/lib/Plack/App/SeeAlso.pm @@ -14,7 +14,6 @@ use Plack::Util; use Carp qw(croak); use Scalar::Util qw(blessed reftype); use Try::Tiny; -use Data::Dumper; use JSON; use Encode; @@ -41,26 +40,34 @@ sub prepare_app { my $self = shift; return if $self->{app}; # already initialized - # get default values from module variables + # get default configuration from module variables $self->{Stylesheet} = 'seealso.xsl' unless exists $self->{Stylesheet}; foreach (@PROPERTIES) { no strict 'refs'; - $self->$_( ${ref($self)."::$_"} // '' ) unless exists $self->{$_}; + unless (exists $self->{$_}) { + $self->{$_} = ${ref($self)."::$_"} // ''; + } } + # validate and normalize configuration $self->{ShortName} = sprintf '%.16s', $self->{ShortName} // ''; $self->{LongName} = sprintf '%.48s', $self->{LongName} // '' ; $self->{Description} = sprintf '%.1024s', $self->{Description} // ''; $self->{Tags} = sprintf '%.256s', $self->{Tags} // ''; $self->{Attribution} = sprintf '%.256s', $self->{Attribution} // ''; + my $examples = $self->{Examples}; + $examples = [] unless ref $examples and reftype $examples eq 'ARRAY'; + $self->{Examples} = [ + grep { ref $_ and reftype($_) eq 'HASH' and $_->{id} } @$examples + ]; + # TODO: validate # Stylesheet # Formats # Contact # Source # DateModified - # Examples my %formats = %{ $self->{Formats} || { } }; delete $formats{$_} for (qw(opensearchdescription seealso _)); @@ -79,7 +86,6 @@ sub prepare_app { $formats{seealso} = [ $f->app( sub { $self->query(@_) } ), $f->type ]; my $app = unAPI( %formats ); - $app = Plack::Middleware::JSONP->wrap($app); if ($self->{Stylesheet}) { @@ -105,7 +111,7 @@ sub call { Plack::Util::response_cb( $result, sub { my $res = shift; return unless $res->[0] == 300; - my $base = $self->base || Plack::Request->new($env)->base; + my $base = $self->{base} || Plack::Request->new($env)->base; my $xsl = $self->{Stylesheet}; $xsl = ''; $xsl .= "\n\n"; @@ -126,8 +132,7 @@ sub openSearchDescription { xmlns:seealso="http://ws.gbv.de/seealso/schema/">'; my @prop = ( - map { $_ => $_ } qw(ShortName LongName Description Tags - Contact Developer Attribution), + map { $_ => $_ } qw(ShortName LongName Description Tags Contact Developer Attribution), DateModified => 'dcterms:modified', Source => 'dc:source', ); @@ -138,7 +143,7 @@ sub openSearchDescription { push @xml, " <$tag>"._xmlescape($value).""; } - foreach (@{ $self->Examples || [] }) { + foreach (@{ $self->{Examples} || [] }) { my $id = _xmlescape($_->{id}); push @xml, ""; }