| 1 | package Catalyst::Plugin::Sitemap; | ||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||
| 3 | # ABSTRACT: Sitemap support for Catalyst. | ||||||||||||||
| 4 | 2 | $Catalyst::Plugin::Sitemap::VERSION = '1.0.3'; | |||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 2 | ▶ | use Moose::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 2 | ▶ | no warnings qw/uninitialized/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 2 | ▶ | use WWW::Sitemap::XML; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | 2 | has sitemap => ( | |||||||||||||
| 15 | is => 'ro', | ||||||||||||||
| 16 | builder => '_build_sitemap', | ||||||||||||||
| 17 | lazy => 1, | ||||||||||||||
| 18 | ); | ||||||||||||||
| 19 | |||||||||||||||
| 20 | 1 | ▶ | sub sitemap_as_xml { | ||||||||||||
|
Subroutine
sitemap_as_xml: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 21 | 1 | return $_[0]->sitemap->as_xml->toString; | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 1 | ▶ | sub _build_sitemap { | ||||||||||||
|
Subroutine
_build_sitemap: called CC=3 SCAR=11.0
| |||||||||||||||
| 25 | 1 | my $self = shift; | |||||||||||||
| 26 | |||||||||||||||
| 27 | 1 | my $sitemap = WWW::Sitemap::XML->new; | |||||||||||||
| 28 | |||||||||||||||
| 29 | 1 | for my $controller ( map { $self->controller($_) } $self->controllers ) { | |||||||||||||
| 30 | 1 | for my $action ( $controller->get_action_methods ) { | |||||||||||||
| 31 | 11 | $self->_add_controller_action_to_sitemap( $sitemap, $controller, $action ); | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | } | ||||||||||||||
| 34 | |||||||||||||||
| 35 | 1 | return $sitemap; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 11 | ▶ | sub _add_controller_action_to_sitemap { | ||||||||||||
|
Subroutine
_add_controller_action_to_sitemap: called CC=8 SCAR=20.9
| |||||||||||||||
| 39 | 11 | my( $self, $sitemap, $controller, $act ) = @_; | |||||||||||||
| 40 | |||||||||||||||
| 41 | 11 | my $action = $controller->action_for($act->name); | |||||||||||||
| 42 | |||||||||||||||
| 43 | 11 | ▶ | my $attr = $action->attributes->{Sitemap} or return; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | |||||||||||||||
| 45 | 4 | ▶ | die "more than one attribute 'Sitemap' for sub ", $act->fully_qualified_name | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | if @$attr > 1; | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 4 | my @attr = split /\s*(?:,|=>)\s*/, $attr->[0]; | |||||||||||||
| 49 | |||||||||||||||
| 50 | 4 | my %uri_params; | |||||||||||||
| 51 | |||||||||||||||
| 52 | 4 | ▶ | if ( @attr == 1 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 53 | 2 | ▶ | if ( $attr[0] eq '*' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 54 | 1 | my $sitemap_method = $action->name . "_sitemap"; | |||||||||||||
| 55 | |||||||||||||||
| 56 | 1 | ▶ | return $controller->$sitemap_method( $self, $sitemap ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | if $controller->can($sitemap_method); | ||||||||||||||
| 58 | } | ||||||||||||||
| 59 | elsif ( $attr[0] + 0 > 0 ) { # it's a number | ||||||||||||||
| 60 | 1 | $uri_params{priority} = $attr[0]; | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | } | ||||||||||||||
| 63 | elsif ( @attr > 0 ) { | ||||||||||||||
| 64 | 1 | %uri_params = @attr; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 3 | $uri_params{loc} = $self->uri_for_action( $action->private_path ); | |||||||||||||
| 68 | |||||||||||||||
| 69 | 3 | $sitemap->add(%uri_params); | |||||||||||||
| 70 | } | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 2 | 1; | |||||||||||||
| 73 | |||||||||||||||
| 74 | __END__ | ||||||||||||||