« lib/OAuthomatic/UserInteraction/ViaMicroWeb.pm
↑ Summary
blib/lib/OAuthomatic/OAuthInteraction.pm »
| 1 | package OAuthomatic::Config; | ||
| 2 | # ABSTRACT: Aggregated bag for various OAuthomatic parameters, separated from main class to make passing them around easier. | ||
| 3 | |||
| 4 | use Moose; | ||
| 5 | use MooseX::AttributeShortcuts; | ||
| 6 | use MooseX::Types::Path::Tiny qw/AbsDir AbsPath/; | ||
| 7 | use Carp; | ||
| 8 | use Path::Tiny; | ||
| 9 | use Try::Tiny; | ||
| 10 | use OAuthomatic::Types; | ||
| 11 | use namespace::sweep; | ||
| 12 | |||
| 13 | # FIXME: validation of params syntax (especially URLs and html_dir) | ||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | has 'app_name' => ( | ||
| 18 | is => 'ro', isa => 'Str', required => 1); | ||
| 19 | |||
| 20 | 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 | my $self = shift; | ||
| 27 | 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 | my $command = Browser::Open::open_browser_cmd(); | ||
| 32 | print "[OAuthomatic] Will use browser $command\n" if $self->debug; | ||
| 33 | return $command; | ||
| 34 | }); | ||
| 35 | |||
| 36 | has 'html_dir' => ( | ||
| 37 | is => 'lazy', isa => AbsDir, coerce=>1, | ||
| 38 | default => sub { | ||
| 39 | my $self = shift; | ||
| 40 | require File::ShareDir; | ||
| 41 | my $share_dir; | ||
| 42 | try { | ||
| 43 | $share_dir = path(File::ShareDir::dist_dir("OAuthomatic")); | ||
| 44 | } catch { | ||
| 45 | if(/Failed to find share dir/) { | ||
| 46 | # Look for local development run | ||
| 47 | $share_dir = path(__FILE__)->absolute->parent->parent->parent->child("share"); | ||
| 48 | print "[OAuthomatic] Can't find instaled html_dir, trying $share_dir\n" if $self->debug; | ||
| 49 | } | ||
| 50 | OAuthomatic::Error::Generic->throw( | ||
| 51 | ident => "Can not find html_dir", | ||
| 52 | extra => $_) | ||
| 53 | unless ($share_dir && $share_dir->exists); | ||
| 54 | }; | ||
| 55 | my $hd = $share_dir->child("oauthomatic_html"); | ||
| 56 | OAuthomatic::Error::Generic->throw( | ||
| 57 | ident => "Invalid html_dir", | ||
| 58 | extra => "Directory $hd not found") | ||
| 59 | unless $hd->is_dir; | ||
| 60 | print "[OAuthomatic] Using own HTML templates from: $hd\n" if $self->debug; | ||
| 61 | return $hd; | ||
| 62 | }); | ||
| 63 | |||
| 64 | has 'debug' => (is => 'ro', isa => 'Bool'); | ||
| 65 | |||
| 66 | 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 |