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