| 1 | package OAuthomatic::Config; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Aggregated bag for various OAuthomatic parameters, separated from main class to make passing them around easier. | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use MooseX::AttributeShortcuts; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use MooseX::Types::Path::Tiny qw/AbsDir AbsPath/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use OAuthomatic::Types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use namespace::sweep; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # FIXME: validation of params syntax (especially URLs and html_dir) | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 5 | has 'app_name' => ( | |||||||||||||||||||||||||||
| 18 | is => 'ro', isa => 'Str', required => 1); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 5 | has 'password_group' => ( | |||||||||||||||||||||||||||
| 21 | is => 'ro', isa => 'Str', default => 'OAuthomatic tokens'); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | has 'browser' => ( | ||||||||||||||||||||||||||||
| 24 | is => 'ro', isa => 'Str', default => sub { | ||||||||||||||||||||||||||||
| 25 | # FIXME: consider trying more than one command (Browser::Open supports it) | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 27 | 0 | require Browser::Open; | |||||||||||||||||||||||||||
| 28 | # Note: on Debian/Ubuntu it uses sensible-browser which checks BROWSER, then | ||||||||||||||||||||||||||||
| 29 | # tries gnome-www-browser and few others. Reasonable way to reconfigure: | ||||||||||||||||||||||||||||
| 30 | # sudo update-alternatives --config gnome-www-browser | ||||||||||||||||||||||||||||
| 31 | 0 | my $command = Browser::Open::open_browser_cmd(); | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | print "[OAuthomatic] Will use browser $command\n" if $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | return $command; | |||||||||||||||||||||||||||
| 34 | 5 | }); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | has 'html_dir' => ( | ||||||||||||||||||||||||||||
| 37 | is => 'lazy', isa => AbsDir, coerce=>1, | ||||||||||||||||||||||||||||
| 38 | default => sub { | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 40 | 0 | require File::ShareDir; | |||||||||||||||||||||||||||
| 41 | 0 | my $share_dir; | |||||||||||||||||||||||||||
| 42 | try { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | $share_dir = path(File::ShareDir::dist_dir("OAuthomatic")); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 44 | } catch { | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if(/Failed to find share dir/) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | # Look for local development run | ||||||||||||||||||||||||||||
| 47 | 0 | $share_dir = path(__FILE__)->absolute->parent->parent->parent->child("share"); | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | print "[OAuthomatic] Can't find instaled html_dir, trying $share_dir\n" if $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | OAuthomatic::Error::Generic->throw( | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | ident => "Can not find html_dir", | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$share_dir and $share_dir->exists
MC/DC0%0/2
$share_dir and $share_dir->exists
$share_dir
$share_dir->exists
Truth table0%0/3
A and B
A= $share_dirB= $share_dir->exists
| |||||||||||||||||||||||||||||
| 52 | extra => $_) | ||||||||||||||||||||||||||||
| 53 | unless ($share_dir && $share_dir->exists); | ||||||||||||||||||||||||||||
| 54 | 0 | }; | |||||||||||||||||||||||||||
| 55 | 0 | my $hd = $share_dir->child("oauthomatic_html"); | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | OAuthomatic::Error::Generic->throw( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | ident => "Invalid html_dir", | ||||||||||||||||||||||||||||
| 58 | extra => "Directory $hd not found") | ||||||||||||||||||||||||||||
| 59 | unless $hd->is_dir; | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | print "[OAuthomatic] Using own HTML templates from: $hd\n" if $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | return $hd; | |||||||||||||||||||||||||||
| 62 | 5 | }); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 5 | has 'debug' => (is => 'ro', isa => 'Bool'); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 5 | 1; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =pod | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head1 NAME | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | OAuthomatic::Config - Aggregated bag for various OAuthomatic parameters, separated from main class to make passing them around easier. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head1 VERSION | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | version 0.0201 | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | my $config = OAuthomatic::Config->new( | ||||||||||||||||||||||||||||
| 85 | app_name => "News trend parser", | ||||||||||||||||||||||||||||
| 86 | password_group => "OAuth tokens (personal)", | ||||||||||||||||||||||||||||
| 87 | html_dir => "/usr/local/share/custom/oauthomatic-green", | ||||||||||||||||||||||||||||
| 88 | browser => "opera", | ||||||||||||||||||||||||||||
| 89 | debug => 1, | ||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | See L<OAuthomatic> for description of all parameters. | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | This object is used as simple bag to pass a few common params | ||||||||||||||||||||||||||||
| 97 | between various L<OAuthomatic> modules. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl> | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | This software is copyright (c) 2015 by Marcin Kasperski. | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 108 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||