File Coverage

blib/lib/Net/Delicious/Config.pm
Criterion Covered Total %
statement 6 42 14.2
branch 0 2 0.0
condition n/a
subroutine 2 7 28.5
pod 0 5 0.0
total 8 56 14.2


line stmt bran cond sub pod time code
1             # $Id: Config.pm,v 1.18 2008/03/03 16:55:04 asc Exp $
2              
3             package Net::Delicious::Config;
4             $Net::Delicious::Config::VERSION = '1.14';
5              
6             =head1 NAME
7              
8             Net::Delicious::Config - config handler for Net::Delicious.
9              
10             =head2 SYNOPSIS
11              
12             Config handler for Net::Delicious.
13              
14             =head1 DESCRIPTION
15              
16             Internally, Net::Delicious uses an "ini" style Config::Simple object to keep track of its
17             various settings. These include user credentials, endpoints as well as API request and
18             response parameters.
19              
20             While there is no expectation that a user will ever need to change anything than their basic
21             login information, it is possible to override any of the default configuration options. If, you
22             know, you're in to that kind of thing.
23              
24             The only caveat is that in order to override default configuaration for request and response
25             properties you will need to pass the Net::Delicious object constructor a Config::Simple object
26             or the path to a valid "ini" style config file. (Arguments passed to the constructor as a hash
27             reference are assumed to be part of the default B configs.)
28              
29             It is important to remember that these config options, and definitions, are not meant to be a
30             complete web services description nor do they play one on TV. They are some bare-bones glue
31             to allow users the ability to define their own settings in the event that this package falls out
32             of sync with the API or they've dreampt up some wacky project that uses Net::Delicious.
33              
34             =cut
35              
36             =head1 DEFAULT CONFIGS
37              
38             These are outlined in the POD for the L object constructor. They
39             are basically anything define in the B<[delicious]> block.
40              
41             Default API response configs are defined in Net::Delicious::Constants::Config::DELICIOUS_CFG_STD.
42              
43             =cut
44              
45             =head1 API CALL CONFIGS
46              
47             API call configs are the set of allowable parameters that may be sent to del.icio.us
48             with a given method call along with flags to indicate whether an argument is required
49             or needs some special magic DWIM munging.
50              
51             The basic syntax for block names is the string B, the lower-case name of the
52             API class (posts, user, etc.) followed by the lower-case name of the method all joined by
53             underbars.
54              
55             The basic syntax for block arguments is the name of the API parameter followed by a single
56             string containing multiple options separated by semi-colons. As of this writing, there aren't
57             very many options. The first is the string B if (drumroll) the parameter is required.
58             The only other recognized option is the string B which will tell the argument parser to
59             DWIM if the user passes boolean true or false.
60              
61             For example :
62              
63             [delicious_posts_add]
64             url="required"
65             description=""
66             extended=""
67             tags=""
68             dt=""
69             shared=";no"
70             replace=";no"
71              
72             If a method class is nested, the syntax requires that all B strings be replaced by underbars.
73             For example B is defined as :
74            
75             [delicious_tags_bundles_set]
76             bundle="required"
77             tags="required"
78              
79             Default API response configs are defined in Net::Delicious::Constants::Config::DELICIOUS_CFG_API.
80              
81             =cut
82              
83             =head1 API RESPONSE CONFIGS
84              
85             API response configs define the properties that are expected to be returned in a given
86             method call and mapped to object methods.
87              
88             As of this writings, all properites are defined in the B block.
89              
90             The basic syntax for block arguments is the lower-case name of the Net::Delicious object class
91             followed by a comma-separated list of properties/methods. Unless already defined in their parent
92             package, "get" methods for each property will be automagically created.
93              
94             [delicious_properties]
95             date="tag,date,count,user"
96             post="description,extended,href,time,parent,tag,others,shared"
97             bundle="name,tag"
98             user="name"
99             subscriptions="user,tag"
100             tag="tag,count"
101              
102             Default API response configs are defined in Net::Delicious::Constants::Config::DELICIOUS_CFG_PROPERTIES.
103              
104             =cut
105              
106 1     1   1137 use Config::Simple;
  1         18732  
  1         97  
107 1     1   51 use Net::Delicious::Constants qw (:config);
  1         1  
  1         12  
108              
109             sub mk_config {
110 0     0 0   my $pkg = shift;
111 0           my $args = shift;
112              
113 0           my $cfg = Config::Simple->new(syntax => "ini");
114 0           $cfg->set_block("delicious", $args);
115              
116 0           return $cfg;
117             }
118              
119             sub merge_configs {
120 0     0 0   my $pkg = shift;
121 0           my $cfg = shift;
122              
123 0           $pkg->merge_defaults($cfg, "delicious", {DELICIOUS_CFG_STD});
124 0           $pkg->merge_api_parameters($cfg);
125 0           $pkg->merge_rsp_properties($cfg);
126              
127 0           return 1;
128             }
129              
130             sub merge_rsp_properties {
131 0     0 0   my $pkg = shift;
132 0           my $cfg = shift;
133              
134 0           my $defaults = {DELICIOUS_CFG_PROPERTIES};
135 0           my $block = "delicious_properties";
136              
137 0           $pkg->merge_defaults($cfg, $block, $defaults);
138 0           return 1;
139             }
140              
141             sub merge_api_parameters {
142 0     0 0   my $pkg = shift;
143 0           my $cfg = shift;
144              
145 0           my $defaults = {DELICIOUS_CFG_API};
146              
147 0           foreach my $class (keys %$defaults) {
148              
149 0           foreach my $meth (keys %{$defaults->{$class}}) {
  0            
150 0           my $block = join("_", "delicious", $class, $meth);
151 0           $pkg->merge_defaults($cfg, $block, $defaults->{$class}->{$meth});
152             }
153             }
154              
155 0           return 1;
156             }
157              
158             sub merge_defaults {
159 0     0 0   my $pkg = shift;
160 0           my $cfg = shift;
161 0           my $block = shift;
162 0           my $defaults = shift;
163              
164 0           my $input = $cfg->param(-block => $block);
165              
166 0           foreach my $key (keys %$defaults) {
167              
168 0           my $dkey = join(".", $block, $key);
169              
170 0 0         if (! exists($input->{$key})) {
171 0           $cfg->param($dkey, $defaults->{$key});
172             }
173             }
174              
175 0           return 1;
176             }
177              
178             =head1 VERSION
179              
180             1.13
181              
182             =head1 DATE
183              
184             $Date: 2008/03/03 16:55:04 $
185              
186             =head1 AUTHOR
187              
188             Aaron Straup Cope Eascope@cpan.orgE
189              
190             =head1 LICENSE
191              
192             Copyright (c) 2004-2008 Aaron Straup Cope. All rights reserved.
193              
194             This is free software, you may use it and distribute it under the
195             same terms as Perl itself.
196              
197             =cut
198              
199             return 1;