File Coverage

lib/OAuthomatic/Config.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


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