File Coverage

blib/lib/ASP4/API.pm
Criterion Covered Total %
statement 30 34 88.2
branch 2 4 50.0
condition n/a
subroutine 11 15 73.3
pod 5 7 71.4
total 48 60 80.0


line stmt bran cond sub pod time code
1              
2             package ASP4::API;
3              
4 4     4   63599 use strict;
  4         6  
  4         112  
5 4     4   18 use warnings 'all';
  4         7  
  4         135  
6 4     4   1224 use ASP4::ConfigLoader;
  4         6  
  4         95  
7 4     4   1377 use ASP4::HTTPContext;
  4         11  
  4         107  
8 4     4   1836 use ASP4::UserAgent;
  4         10  
  4         119  
9 4     4   1498 use Data::Properties::YAML;
  4         23575  
  4         102  
10 4     4   1338 use ASP4::Test::Fixtures;
  4         8  
  4         858  
11              
12             sub new
13             {
14 4     4 0 4259 my ($class) = @_;;
15            
16 4         29 my $config = ASP4::ConfigLoader->load;
17            
18             # Our test fixtures:
19 4 50       55 my $test_data = ASP4::Test::Fixtures->new(
20             properties_file => $config->web->application_root . '/etc/test_fixtures.yaml'
21             ) if -f $config->web->application_root . '/etc/test_fixtures.yaml';
22            
23             # Our diagnostic messages:
24 4 50       59686 my $properties = Data::Properties::YAML->new(
25             properties_file => $config->web->application_root . '/etc/properties.yaml'
26             ) if -f $config->web->application_root . '/etc/properties.yaml';
27            
28 4         13260 return bless {
29             test_data => $test_data,
30             properties => $properties,
31             ua => ASP4::UserAgent->new()
32             }, $class;
33             }# end new()
34              
35              
36 0     0 0 0 sub test_data { shift->{test_data} }
37 0     0 1 0 sub properties { shift->{properties} }
38 5205     5205 1 210688 sub ua { shift->{ua} }
39 1     1 1 3 sub context { ASP4::HTTPContext->current }
40 0     0 1 0 sub config { ASP4::ConfigLoader->load }
41              
42 0     0 1 0 sub data { shift->test_data } # Deprecated! - for Apache2::ASP compat only.
43              
44              
45             sub DESTROY
46             {
47 1     1   274 my $s = shift;
48 1         54 undef(%$s);
49             }# end DESTROY()
50              
51             1;# return true:
52              
53             =pod
54              
55             =head1 NAME
56              
57             ASP4::API - Your ASP4 Web App's Public API
58              
59             =head1 SYNOPSIS
60              
61             #!/usr/bin/perl -w
62            
63             use strict;
64             use warnings 'all';
65             use ASP4::API;
66            
67             my $api; BEGIN { $api = ASP4::API->new }
68            
69             # Now you can use your other classes:
70             use My::User;
71             use My::Product;
72             use My::Foo;
73            
74             # Use the API:
75            
76             my $res = $api->ua->get('/index.asp');
77             if( $res->is_success ) {
78             print $res->content;
79             }
80            
81             # Access your test data:
82             warn $res->test_data->contact_form->email;
83            
84             # Access your properties YAML:
85             warn $res->properties->contact_form->email->is_missing;
86            
87             # Access the application config:
88             warn $api->config->system->settings->foo;
89              
90             =head1 DESCRIPTION
91              
92             C is B - specifically when writing tests
93             for the actual web pages themselves.
94              
95             =head2 Example Unit Test
96              
97             #!/usr/bin/perl -w
98            
99             use strict;
100             use warnings 'all';
101             use Test::More 'no_plan';
102            
103             use ASP4::API;
104            
105             ok(
106             my $api = ASP4::API->new, "Got api"
107             );
108             is(
109             $api->ua->get('/hello.asp')->content => 'Hello World!',
110             'Website is friendly'
111             );
112              
113             =head1 PUBLIC PROPERTIES
114              
115             =head2 ua
116              
117             Returns an L that can be used to interact with pages on your website.
118              
119             =head2 context
120              
121             Returns the current instance of L in use.
122              
123             =head2 config
124              
125             Returns the L object for the web application.
126              
127             =head2 properties
128              
129             Returns an object representing your C file.
130              
131             =head2 data
132              
133             Returns an object representing your C file.
134              
135             =cut
136