| 1 | package WWW::TypePad::CmdLine; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use 5.008_001; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Config::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use File::HomeDir; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Getopt::Long qw( :config pass_through ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use WWW::TypePad; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 1 | our $Config = File::Spec->catfile( | |||||||||||||||||||||||||||||||
| 14 | File::HomeDir->my_data, '.www-typepad-info' | ||||||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||||||
| 16 | 1 | our $ConfigObj; | |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 1 | GetOptions( 'config=s' => \$Config ); | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub config_file { | ||||||||||||||||||||||||||||||
|
Subroutine
config_file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 21 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 22 | 0 | return $Config; | |||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub config { | ||||||||||||||||||||||||||||||
|
Subroutine
config: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 26 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return $ConfigObj ||= Config::Tiny->read( $class->config_file ); | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$WWW::TypePad::CmdLine::ConfigObj ||= "Config::Tiny"->read($class->config_file)
MC/DC0%0/2
$WWW::TypePad::CmdLine::ConfigObj ||= "Config::Tiny"->read($class->config_file)
$WWW::TypePad::CmdLine::ConfigObj
"Config::Tiny"->read($class->config_file)
Truth table0%0/3
A ||= B
A= $WWW::TypePad::CmdLine::ConfigObjB= "Config::Tiny"->read($class->config_file)
| |||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub initialize { | ||||||||||||||||||||||||||||||
|
Subroutine
initialize: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 31 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 32 | 0 | my( %p ) = @_; | |||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 0 | my $tp; | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 0 | my $config = $class->config; | |||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ( !defined $config && $p{requires_auth} ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
not defined $config and $p{"requires_auth"}
MC/DC0%0/2
not defined $config and $p{"requires_auth"}
not defined $config
$p{"requires_auth"}
Truth table0%0/3
not(A) and B
A= not defined $configB= $p{"requires_auth"}
| |||||||||||||||||||||||||||||||||
| 38 | $tp = WWW::TypePad->new( | ||||||||||||||||||||||||||||||||
| 39 | ( $ENV{TP_HOST} ? ( host => $ENV{TP_HOST} ) : () ), | ||||||||||||||||||||||||||||||||
| 40 | consumer_key => $ENV{TP_CONSUMER_KEY}, | ||||||||||||||||||||||||||||||||
| 41 | consumer_secret => $ENV{TP_CONSUMER_SECRET}, | ||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | die "TP_CONSUMER_KEY and TP_CONSUMER_SECRET required in ENV" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tp->consumer_key and $tp->consumer_secret
MC/DC0%0/2
$tp->consumer_key and $tp->consumer_secret
$tp->consumer_key
$tp->consumer_secret
Truth table0%0/3
A and B
A= $tp->consumer_keyB= $tp->consumer_secret
| |||||||||||||||||||||||||||||||||
| 45 | unless $tp->consumer_key && $tp->consumer_secret; | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 0 | $class->new_config( $tp ); | |||||||||||||||||||||||||||||||
| 48 | } elsif ( $p{requires_auth} ) { | ||||||||||||||||||||||||||||||||
| 49 | $tp = WWW::TypePad->new( | ||||||||||||||||||||||||||||||||
| 50 | ( $config->{app}{host} ? ( host => $config->{app}{host} ) : () ), | ||||||||||||||||||||||||||||||||
| 51 | consumer_key => $config->{app}{consumer_key}, | ||||||||||||||||||||||||||||||||
| 52 | consumer_secret => $config->{app}{consumer_secret}, | ||||||||||||||||||||||||||||||||
| 53 | access_token => $config->{auth}{access_token}, | ||||||||||||||||||||||||||||||||
| 54 | access_token_secret => $config->{auth}{access_token_secret}, | ||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||||||
| 57 | 0 | $tp = WWW::TypePad->new; | |||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 0 | return $tp; | |||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub new_config { | ||||||||||||||||||||||||||||||
|
Subroutine
new_config: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 64 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 65 | 0 | my( $tp ) = @_; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 0 | $ConfigObj = Config::Tiny->new; | |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 0 | print <<MSG; | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | Welcome to WWW::TypePad! Before we get started, we'll need to link our | ||||||||||||||||||||||||||||||||
| 72 | local configuration to your TypePad account. | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | First, you'll need to authorize this application in your web browser. | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | MSG | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 0 | my $auth_uri = $tp->oauth->get_authorization_url( | |||||||||||||||||||||||||||||||
| 79 | callback => 'oob', | ||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ( -x '/usr/bin/open' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | 0 | print <<MSG; | |||||||||||||||||||||||||||||||
| 84 | We're opening this URL in your web browser: | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | $auth_uri | ||||||||||||||||||||||||||||||||
| 87 | MSG | ||||||||||||||||||||||||||||||||
| 88 | 0 | system 'open', $auth_uri; | |||||||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||||||||
| 90 | 0 | print <<MSG; | |||||||||||||||||||||||||||||||
| 91 | Open this URL in your web browser: | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | $auth_uri | ||||||||||||||||||||||||||||||||
| 94 | MSG | ||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 0 | print <<MSG; | |||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | When you've allowed access to this application, you'll get a verifier | ||||||||||||||||||||||||||||||||
| 100 | code that we'll need to complete the handshake. | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | MSG | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 0 | print "Enter the verifier code: "; | |||||||||||||||||||||||||||||||
| 105 | 0 | chomp( my $verifier = <STDIN> ); | |||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 0 | my( $access_token, $access_token_secret ) = | |||||||||||||||||||||||||||||||
| 108 | $tp->oauth->request_access_token( verifier => $verifier ); | ||||||||||||||||||||||||||||||||
| 109 | 0 | $tp->access_token( $access_token ); | |||||||||||||||||||||||||||||||
| 110 | 0 | $tp->access_token_secret( $access_token_secret ); | |||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | 0 | my $obj = $tp->users->get( '@self' ); | |||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | die 'Request for @self gave us empty result' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 114 | unless $obj; | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 0 | print <<MSG; | |||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | Great! We've identified you as "$obj->{displayName}". | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | We're going to save your configuration in the following file, in case you'd | ||||||||||||||||||||||||||||||||
| 121 | like to access or change it in the future: | ||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | $Config | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | MSG | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | $ConfigObj->{app} = { | ||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | ( $tp->host ne 'api.typepad.com' ? ( host => $tp->host ) : () ), | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 129 | consumer_key => $tp->consumer_key, | ||||||||||||||||||||||||||||||||
| 130 | consumer_secret => $tp->consumer_secret, | ||||||||||||||||||||||||||||||||
| 131 | }; | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | $ConfigObj->{auth} = { | ||||||||||||||||||||||||||||||||
| 134 | 0 | access_token => $access_token, | |||||||||||||||||||||||||||||||
| 135 | access_token_secret => $access_token_secret, | ||||||||||||||||||||||||||||||||
| 136 | }; | ||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | 0 | $ConfigObj->write( $class->config_file ); | |||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 1 | 1; | |||||||||||||||||||||||||||||||
| 142 | __END__ | ||||||||||||||||||||||||||||||||