lib/OAuthomatic/Config.pm

filter: Statementstmt 62.5% 30 / 48 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 8 / 12 Podpod n/a totaltotal 49.3% 38 / 77 SCAR 28.4
CC
8
Cov
48%
__ANON__
30.0
__ANON__
12.0
__ANON__
6.0
CRAP 17.2
« blib/lib/OAuthomatic/UserInteraction/ConsolePrompts.pm ↑ Summary lib/OAuthomatic/UserInteraction/ConsolePrompts.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 # FIXME: split into Site (various oauth-related) and Config (other settings).
5 # FIXME: provide predefined sites
6 # FIXME: server, not site
7  
8 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use MooseX::AttributeShortcuts;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use MooseX::Types::Path::Tiny qw/AbsDir AbsPath/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use OAuthomatic::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use namespace::sweep;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # FIXME: validation of params syntax (especially URLs and html_dir)
18  
19  
20  
21 5 has 'app_name' => (
22 is => 'ro', isa => 'Str', required => 1);
23  
24 5 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 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
31 0 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 0 my $command = Browser::Open::open_browser_cmd();
36 0 ▶ print "[OAuthomatic] Will use browser $command\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
37 0 return $command;
38 5 });
39  
40 has 'html_dir' => (
41 is => 'lazy', isa => AbsDir, coerce=>1,
42 default => sub {
43 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
44 0 require File::ShareDir;
45 0 my $share_dir;
46 try {
47 0 ▶ $share_dir = path(File::ShareDir::dist_dir("OAuthomatic"));
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 } catch {
49 0 ▶ if(/Failed to find share dir/) {
Subroutine __ANON__: not called CC=5 SCAR=34.0
Branch: 1 branch
BranchTrueFalseTotal
if (/Failed to find share dir/) 0 0 0
50 # Look for local development run
51 0 $share_dir = path(__FILE__)->absolute->parent->parent->parent->child("share");
52 0 ▶ print "[OAuthomatic] Can't find instaled html_dir, trying $share_dir\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
53 }
54 OAuthomatic::Error::Generic->throw(
55 0 ▶ ident => "Can not find html_dir",
Branch: 1 branch
BranchTrueFalseTotal
unless $share_dir and $share_dir->exists 0 0 0
Condition0%0/3
$share_dir and $share_dir->exists
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
56 extra => $_)
57 unless ($share_dir && $share_dir->exists);
58 0 };
59 0 my $hd = $share_dir->child("oauthomatic_html");
60 0 ▶ OAuthomatic::Error::Generic->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $hd->is_dir 0 0 0
61 ident => "Invalid html_dir",
62 extra => "Directory $hd not found")
63 unless $hd->is_dir;
64 0 ▶ print "[OAuthomatic] Using own HTML templates from: $hd\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
65 0 return $hd;
66 5 });
67  
68 5 has 'debug' => (is => 'ro', isa => 'Bool');
69  
70 5 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.01
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
« blib/lib/OAuthomatic/UserInteraction/ConsolePrompts.pm ↑ Summary lib/OAuthomatic/UserInteraction/ConsolePrompts.pm »