| 1 | package Search::Sitemap::Types; | ||||||||||||||||||||||
| 2 | 4 | $Search::Sitemap::Types::VERSION = '2.13_01'; | |||||||||||||||||||||
| 3 | 4 | ▶ | use 5.008003; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 4 | our $AUTHORITY = 'cpan:JASONK'; | |||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 4 | ▶ | use Class::Load; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | 4 | ▶ | use MooseX::Types -declare => [qw( | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | SitemapURL SitemapUrlStore SitemapChangeFreq SitemapLastMod SitemapPriority | ||||||||||||||||||||||
| 11 | XMLPrettyPrintValue XMLTwig SitemapPinger | ||||||||||||||||||||||
| 12 | 4 | )]; | |||||||||||||||||||||
| 13 | 4 | ▶ | use MooseX::Types::Moose qw( Object HashRef Str Int Bool Num ); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | 4 | ▶ | use MooseX::Types::URI qw( Uri ); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 15 | 4 | ▶ | use POSIX qw( strftime ); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | 4 | class_type( 'Search::Sitemap::URL' ); | |||||||||||||||||||||
| 18 | 4 | subtype SitemapURL, as 'Search::Sitemap::URL'; | |||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | coerce SitemapURL, | ||||||||||||||||||||||
| 21 | 0 | ▶ | from HashRef, via { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 22 | 0 | Class::Load::load_class( 'Search::Sitemap::URL' ); | |||||||||||||||||||||
| 23 | 0 | Search::Sitemap::URL->new( $_ ); | |||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||
| 25 | 0 | ▶ | from Str, via { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 26 | 0 | Class::Load::load_class( 'Search::Sitemap::URL' ); | |||||||||||||||||||||
| 27 | 0 | Search::Sitemap::URL->new( loc => $_ ); | |||||||||||||||||||||
| 28 | 4 | }; | |||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | 0 | ▶ | subtype XMLPrettyPrintValue, as Str, where { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 31 | 0 | $_ =~ m{ ^ ( | |||||||||||||||||||||
| 32 | none | nsgmls | nice | indented | indented_c | indented_a | cvs | | ||||||||||||||||||||||
| 33 | wrapped | record | record_c | ||||||||||||||||||||||
| 34 | ) $ }x; | ||||||||||||||||||||||
| 35 | 4 | }; | |||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | coerce XMLPrettyPrintValue, | ||||||||||||||||||||||
| 38 | 0 | ▶ | from Int, via { $_ ? 'nice' : 'none' }, | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||
| 39 | 0 | ▶ | from Str, via { $_ ? 'nice' : 'none' }; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||||
| 40 | |||||||||||||||||||||||
| 41 | 0 | ▶ | subtype SitemapChangeFreq, as Str, where { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 42 | 0 | $_ =~ m{ ^ ( | |||||||||||||||||||||
| 43 | always | hourly | daily | weekly | monthly | yearly | never | ||||||||||||||||||||||
| 44 | ) $ }x; | ||||||||||||||||||||||
| 45 | 4 | }; | |||||||||||||||||||||
| 46 | 0 | ▶ | coerce SitemapChangeFreq, from Str, via { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 47 | 0 | my %types = ( | |||||||||||||||||||||
| 48 | a => 'always', | ||||||||||||||||||||||
| 49 | h => 'hourly', | ||||||||||||||||||||||
| 50 | d => 'daily', | ||||||||||||||||||||||
| 51 | w => 'weekly', | ||||||||||||||||||||||
| 52 | m => 'monthly', | ||||||||||||||||||||||
| 53 | y => 'yearly', | ||||||||||||||||||||||
| 54 | n => 'never', | ||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||
| 56 | 0 | ▶ | if ( m{ ^( [ahdwmyn] ) }ix ) { return $types{ lc $1 } } | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 57 | 0 | return; | |||||||||||||||||||||
| 58 | 4 | }; | |||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | 4 | my $lastmod_re = qr/ ^ | |||||||||||||||||||||
| 61 | (\d{4}) # year | ||||||||||||||||||||||
| 62 | \-? | ||||||||||||||||||||||
| 63 | (\d{2})? # month | ||||||||||||||||||||||
| 64 | \-? | ||||||||||||||||||||||
| 65 | (\d{2})? # day | ||||||||||||||||||||||
| 66 | (?: | ||||||||||||||||||||||
| 67 | T | ||||||||||||||||||||||
| 68 | (\d{2}) # hours | ||||||||||||||||||||||
| 69 | : | ||||||||||||||||||||||
| 70 | (\d{2}) # minutes | ||||||||||||||||||||||
| 71 | (?: | ||||||||||||||||||||||
| 72 | :(\d{2}) # seconds | ||||||||||||||||||||||
| 73 | (?: | ||||||||||||||||||||||
| 74 | \.(\d+) # fraction of second | ||||||||||||||||||||||
| 75 | )? | ||||||||||||||||||||||
| 76 | )? | ||||||||||||||||||||||
| 77 | (?: | ||||||||||||||||||||||
| 78 | (Z|[\+\-]?\d{2}:\d{2}) # time zone | ||||||||||||||||||||||
| 79 | )? | ||||||||||||||||||||||
| 80 | )? | ||||||||||||||||||||||
| 81 | $ /xi; | ||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | 39 | ▶ | subtype SitemapLastMod, as Str, where { /$lastmod_re/ }; | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | 4 | class_type 'DateTime'; | |||||||||||||||||||||
| 86 | 4 | class_type 'HTTP::Response'; | |||||||||||||||||||||
| 87 | 4 | class_type 'File::stat'; | |||||||||||||||||||||
| 88 | 4 | class_type 'Path::Class::File'; | |||||||||||||||||||||
| 89 | |||||||||||||||||||||||
| 90 | coerce SitemapLastMod, | ||||||||||||||||||||||
| 91 | 3 | ▶ | from Str, via { | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||||||||||||||
| 92 | 3 | ▶ | if ( $_ eq 'now' ) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 93 | 1 | return strftime( "%Y-%m-%dT%H:%M:%S+00:00", gmtime( time ) ); | |||||||||||||||||||||
| 94 | } elsif ( $_ =~ /^\d+$/ ) { | ||||||||||||||||||||||
| 95 | 2 | return strftime( "%Y-%m-%dT%H:%M:%S+00:00", gmtime( $_ ) ); | |||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||
| 97 | 0 | return $_; | |||||||||||||||||||||
| 98 | }, | ||||||||||||||||||||||
| 99 | 0 | ▶ | from Num, via { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 100 | 0 | return strftime( "%Y-%m-%dT%H:%M:%S+00:00", gmtime( $_ ) ); | |||||||||||||||||||||
| 101 | }, | ||||||||||||||||||||||
| 102 | 7 | ▶ | from 'DateTime', via { | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.6
| |||||||||||||||||||||||
| 103 | 7 | my ( $datetime, $tzoff ) = $_->strftime("%Y-%m-%dT%H:%M:%S","%z"); | |||||||||||||||||||||
| 104 | 7 | ▶ | if ( $tzoff =~ /^([+\-])?(\d\d):?(\d\d)/ ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 105 | 7 | ▶ | $tzoff = sprintf( '%s%02d:%02d', $1 || '+', $2, $3 || 0 ); | ||||||||||||||||||||
|
Condition50%2/4
$1 || '+'
$3 || 0
MC/DC0%0/1
$1 || '+'
$1
MC/DC0%0/1
$3 || 0
$3
Truth table50%1/2
A
A= $1
Truth table50%1/2
A
A= $3
| |||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||
| 107 | 0 | $tzoff = '+00:00'; | |||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||
| 109 | 7 | return $datetime.$tzoff; | |||||||||||||||||||||
| 110 | }, | ||||||||||||||||||||||
| 111 | 2 | ▶ | from 'HTTP::Response', via { | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||
| 112 | 2 | ▶ | my $modtime = $_->last_modified || ( time - $_->current_age ); | ||||||||||||||||||||
|
Condition66%2/3
$_->last_modified || time - $_->current_age
MC/DC0%0/2
$_->last_modified || time - $_->current_age
$_->last_modified
time - $_->current_age
Truth table66%2/3
A || B
A= $_->last_modifiedB= time - $_->current_age
| |||||||||||||||||||||||
| 113 | 2 | return strftime( "%Y-%m-%dT%H:%M:%S+00:00", gmtime( $modtime ) ); | |||||||||||||||||||||
| 114 | }, | ||||||||||||||||||||||
| 115 | 1 | ▶ | from 'File::stat', via { | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 116 | 1 | return strftime( "%Y-%m-%dT%H:%M:%S+00:00", gmtime( $_->mtime ) ); | |||||||||||||||||||||
| 117 | }, | ||||||||||||||||||||||
| 118 | 1 | ▶ | from 'Path::Class::File', via { | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 119 | 1 | return strftime( "%Y-%m-%dT%H:%M:%S+00:00", gmtime( $_->stat->mtime ) ); | |||||||||||||||||||||
| 120 | 4 | }; | |||||||||||||||||||||
| 121 | |||||||||||||||||||||||
| 122 | 0 | ▶ | subtype SitemapPriority, as Num, where { $_ >= 0 && $_ <= 1 }; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||||
| 123 | coerce SitemapPriority, | ||||||||||||||||||||||
| 124 | 0 | ▶ | from Num, via { $_ }; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||
| 125 | |||||||||||||||||||||||
| 126 | 4 | class_type( 'Search::Sitemap::URLStore' ); | |||||||||||||||||||||
| 127 | 4 | subtype SitemapUrlStore, as 'Search::Sitemap::URLStore'; | |||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | coerce SitemapUrlStore, | ||||||||||||||||||||||
| 130 | 0 | ▶ | from HashRef, via { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||
| 131 | 0 | ▶ | my $type = $_->{ 'type' } || 'Memory'; | ||||||||||||||||||||
|
Condition0%0/2
$_->{'type'} || 'Memory'
MC/DC0%0/1
$_->{'type'} || 'Memory'
$_->{'type'}
Truth table0%0/2
A
A= $_->{'type'}
| |||||||||||||||||||||||
| 132 | 0 | ▶ | my $class = $type =~ /::/ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 133 | ? $type | ||||||||||||||||||||||
| 134 | : 'Search::Sitemap::URLStore::'.$type; | ||||||||||||||||||||||
| 135 | 0 | Class::Load::load_class( $class ); | |||||||||||||||||||||
| 136 | 0 | $class->new( $_ ) | |||||||||||||||||||||
| 137 | }, | ||||||||||||||||||||||
| 138 | 0 | ▶ | from Str, via { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 139 | 0 | my $class = 'Search::Sitemap::URLStore::'.$_; | |||||||||||||||||||||
| 140 | 0 | Class::Load::load_class( $class ); | |||||||||||||||||||||
| 141 | 0 | return $class->new; | |||||||||||||||||||||
| 142 | 4 | }; | |||||||||||||||||||||
| 143 | |||||||||||||||||||||||
| 144 | 4 | class_type( 'XML::Twig' ); | |||||||||||||||||||||
| 145 | |||||||||||||||||||||||
| 146 | 4 | class_type( 'Search::Sitemap::Pinger' ); | |||||||||||||||||||||
| 147 | |||||||||||||||||||||||
| 148 | 4 | subtype SitemapPinger, as 'Search::Sitemap::Pinger'; | |||||||||||||||||||||
| 149 | 0 | ▶ | coerce SitemapPinger, from Str, via { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 150 | 0 | my $class = 'Search::Sitemap::Pinger::'.$_; | |||||||||||||||||||||
| 151 | 0 | Class::Load::load_class( $class ); | |||||||||||||||||||||
| 152 | 0 | return $class->new; | |||||||||||||||||||||
| 153 | 4 | }; | |||||||||||||||||||||
| 154 | |||||||||||||||||||||||
| 155 | 4 | class_type( 'LWP::UserAgent' ); | |||||||||||||||||||||
| 156 | |||||||||||||||||||||||
| 157 | 4 | 1; | |||||||||||||||||||||
| 158 | __END__ | ||||||||||||||||||||||