| 1 | package OAuthomatic::ServerDef; | ||||||||||||||||||||
| 2 | # ABSTRACT: Predefined URLs for some services | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 5 | ▶ | use feature 'state'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 5 | ▶ | use namespace::sweep; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 5 | use Exporter::Shiny qw/oauthomatic_predefined_list | |||||||||||||||||||
| 11 | 5 | ▶ | oauthomatic_predefined_for_name/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 5 | ▶ | use Try::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 5 | ▶ | use Scalar::Util qw/blessed reftype/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | use Module::Pluggable | ||||||||||||||||||||
| 16 | 5 | require => 1, # Just warns, so let's keep it | |||||||||||||||||||
| 17 | search_path => ["OAuthomatic::ServerDef"], | ||||||||||||||||||||
| 18 | 5 | ▶ | sub_name => '_oauthomatic_predefined_list'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | sub _calculate_predefined { | ||||||||||||||||||||
| 22 | 0 | ▶ | my %predefined; | ||||||||||||||||||
|
Subroutine
_calculate_predefined: not called CC=8 SCAR=42.8
| |||||||||||||||||||||
| 23 | 0 | foreach my $predef_module (_oauthomatic_predefined_list()) { | |||||||||||||||||||
| 24 | 0 | ▶ | unless($predef_module =~ /^OAuthomatic::ServerDef::(.*)$/x) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | # This should never happen, but let's just ignore | ||||||||||||||||||||
| 26 | 0 | warn "OAuthomatic predef: skipping incorrect module $predef_module\n"; | |||||||||||||||||||
| 27 | 0 | next; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | 0 | my $short_module_name = $1; | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | my $predef; | |||||||||||||||||||
| 32 | 0 | ▶ | unless($predef_module->can('server')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 0 | warn "OAuthomatic predef: bad plugin, module $predef_module does not contain server() function\n"; | |||||||||||||||||||
| 34 | 0 | next; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | try { | ||||||||||||||||||||
| 37 | 0 | ▶ | $predef = $predef_module->server(); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 38 | } catch { | ||||||||||||||||||||
| 39 | 0 | ▶ | warn "OAuthomatic predef: bad plugin, function $predef_module" . "::server() failed: $_\n"; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 40 | 0 | }; | |||||||||||||||||||
| 41 | 0 | ▶ | next unless $predef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | my $predef_type = blessed $predef; | |||||||||||||||||||
| 43 | 0 | ▶ | unless( $predef_type eq 'OAuthomatic::Server' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | ▶ | $predef_type ||= reftype \$predef; | ||||||||||||||||||
|
Condition0%0/3
$predef_type ||= builtin::reftype(\$predef)
MC/DC0%0/2
$predef_type ||= builtin::reftype(\$predef)
$predef_type
builtin::reftype(\$predef)
Truth table0%0/3
A ||= B
A= $predef_typeB= builtin::reftype(\$predef)
| |||||||||||||||||||||
| 45 | 0 | warn "OAuthomatic predef: bad plugin, function $predef_module" . "::server() returned invalid value (expected object of type OAuthomatic::Server, got $predef_type)\n"; | |||||||||||||||||||
| 46 | 0 | next; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | 0 | my $site_name = $predef->site_name; | |||||||||||||||||||
| 49 | 0 | ▶ | unless($site_name eq $short_module_name) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 0 | warn "OAuthomatic predef: bad plugin, $predef_module provided object with bad site_name (got '$site_name', expected '$short_module_name' - matching module name)\n"; | |||||||||||||||||||
| 51 | 0 | next; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | 0 | $predefined{ $site_name } = $predef; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | 0 | return \%predefined; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | sub _predefined { | ||||||||||||||||||||
| 59 | 0 | ▶ | state $predefined = _calculate_predefined(); | ||||||||||||||||||
|
Subroutine
_predefined: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 60 | 0 | return $predefined; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | sub oauthomatic_predefined_list { | ||||||||||||||||||||
| 65 | 0 | ▶ | my $predefined = _predefined(); | ||||||||||||||||||
|
Subroutine
oauthomatic_predefined_list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 66 | 0 | return values %$predefined; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | sub oauthomatic_predefined_for_name { | ||||||||||||||||||||
| 71 | 0 | ▶ | my $name = shift; | ||||||||||||||||||
|
Subroutine
oauthomatic_predefined_for_name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 72 | 0 | my $predefined = _predefined(); | |||||||||||||||||||
| 73 | 0 | ▶ | if( exists $predefined->{$name} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 0 | return $predefined->{$name}; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | 0 | return OAuthomatic::Error::Generic->throw( | |||||||||||||||||||
| 77 | ident => "No such predefined server: $name", | ||||||||||||||||||||
| 78 | extra => "Currently known servers: " | ||||||||||||||||||||
| 79 | . join(", ", sort keys %$predefined) | ||||||||||||||||||||
| 80 | . "\n" | ||||||||||||||||||||
| 81 | . "Maybe you should install OAuthomatic::ServerDef::$name?\n", | ||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 5 | 1; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =pod | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =encoding UTF-8 | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | =head1 NAME | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | OAuthomatic::ServerDef - Predefined URLs for some services | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =head1 VERSION | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | version 0.0201 | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =head1 DESCRIPTION | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | Manages list of definitions of selected OAuth endpoints. This module | ||||||||||||||||||||
| 104 | is mostly used internally, whenever someone writes: | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | OAuthomatic->new( | ||||||||||||||||||||
| 107 | server => 'SomeName', | ||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | it is used to look up appropriate definition. | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | Run script L<oauthomatic_predefined_servers> to list all currently | ||||||||||||||||||||
| 113 | known endpoints. | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | To add server to the list, define module named | ||||||||||||||||||||
| 116 | C<OAuthomatic::ServerDef::ServerName>: | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | package OAuthomatic::ServerDef::ServerName; | ||||||||||||||||||||
| 119 | use strict; | ||||||||||||||||||||
| 120 | use warnings; | ||||||||||||||||||||
| 121 | use OAuthomatic::Server; | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | sub server { | ||||||||||||||||||||
| 124 | return OAuthomatic::Server->new( | ||||||||||||||||||||
| 125 | site_name => 'ServerName', # Must match package name | ||||||||||||||||||||
| 126 | oauth_temporary_url => 'https://...', | ||||||||||||||||||||
| 127 | # ... And the rest | ||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | 1; | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | =head1 EXPORTS FUNCTIONS | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =head2 oauthomatic_predefined_list | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | Returns list of all predefined servers (list of L<OAuthomatic::Server> objects). | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =head2 oauthomatic_predefined_for_name(ServerName) | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | Returns predefined object for given name, or dies. | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =head1 AUTHOR | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl> | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | This software is copyright (c) 2015 by Marcin Kasperski. | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 151 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =cut | ||||||||||||||||||||