OpenInteract2/Brick/Package.pm

filter: Statementstmt 96.1% 25 / 26 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 11 totaltotal 75.4% 40 / 53 CC 2 SCAR 1.4
CC
2
Cov
93%
load
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« OpenInteract2/Brick/WebsiteConfig.pm ↑ Summary OpenInteract2/Setup/RequireSystemClasses.pm »
1 package OpenInteract2::Brick::Package;
2  
3 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 87 ▶use base qw( OpenInteract2::Brick );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 87 ▶use OpenInteract2::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 87 my %INLINED_SUBS = (
8 'package.ini' => 'PACKAGEINI',
9 'MANIFEST.SKIP' => 'MANIFESTSKIP',
10 'spops.ini' => 'SPOPSINI',
11 'action.ini' => 'ACTIONINI',
12 'SQLInstall.pm' => 'SQLINSTALLPM',
13 'Action.pm' => 'ACTIONPM',
14 'App.pm' => 'APPPM',
15 'sample.tmpl' => 'SAMPLETMPL',
16 );
17  
18 87 ▶sub get_name {
Subroutine get_name: called CC=1 SCAR=0.0
Pod undocumented
19 87 return 'package';
20 }
21  
22 9 ▶sub get_resources {
Subroutine get_resources: called CC=1 SCAR=0.0
Pod undocumented
23 return (
24 9 'package.ini' => [ 'package.ini', 'yes' ],
25 'MANIFEST.SKIP' => [ 'MANIFEST.SKIP', 'yes' ],
26 'spops.ini' => [ 'conf spops.ini', 'yes' ],
27 'action.ini' => [ 'conf action.ini', 'yes' ],
28 'SQLInstall.pm' => [ 'OpenInteract2 SQLInstall [% class_name %].pm', 'yes' ],
29 'Action.pm' => [ 'OpenInteract2 Action [% class_name %].pm', 'yes' ],
30 'App.pm' => [ 'OpenInteract2 App [% class_name %].pm', 'yes' ],
31 'sample.tmpl' => [ 'template sample.tmpl', 'no' ],
32 );
33 }
34  
35 8 ▶sub load {
Subroutine load: called CC=2 SCAR=7.4
Pod undocumented
36 8 my ( $self, $resource_name ) = @_;
37 8 my $inline_sub_name = $INLINED_SUBS{ $resource_name };
38 8 ▶ unless ( $inline_sub_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($inline_sub_name) 0 8 8
39 0 OpenInteract2::Exception->throw(
40 "Resource name '$resource_name' not found ",
41 "in ", ref( $self ), "; cannot load content." );
42 }
43 8 return $self->$inline_sub_name();
44 }
45  
46 87 OpenInteract2::Brick->register_factory_type( get_name() => __PACKAGE__ );
47  
48 =pod
49  
50 =head1 NAME
51  
52 OpenInteract2::Brick::Package - All resources used for creating a package
53  
54 =head1 SYNOPSIS
55  
56 oi2_manage create_package --package=foo
57  
58 =head1 DESCRIPTION
59  
60 This class just holds all the static resources used when creating a package.
61  
62 These resources are associated with OpenInteract2 version 1.99_06.
63  
64 =head2 Resources
65  
66 You can grab resources individually using the names below and
67 C<load_resource()> and C<copy_resources_to()>, or you can copy all the
68 resources at once using C<copy_all_resources_to()> -- see
69 L<OpenInteract2::Brick> for details.
70  
71 =over 4
72  
73  
74 =item B<package.ini>
75  
76 =item B<MANIFEST.SKIP>
77  
78 =item B<spops.ini>
79  
80 =item B<action.ini>
81  
82 =item B<SQLInstall.pm>
83  
84 =item B<Action.pm>
85  
86 =item B<App.pm>
87  
88 =item B<sample.tmpl>
89  
90  
91 =back
92  
93 =head1 COPYRIGHT
94  
95 Copyright (c) 2005 Chris Winters. All rights reserved.
96  
97 This library is free software; you can redistribute it and/or modify
98 it under the same terms as Perl itself.
99  
100 =head1 AUTHORS
101  
102  
103 Chris Winters E<lt>chris@cwinters.comE<gt>
104  
105  
106 =cut
107  
108  
109 1 ▶sub PACKAGEINI {
Subroutine PACKAGEINI: called CC=1 SCAR=0.0
Pod undocumented
110 1 return <<'SOMELONGSTRING';
111 [package]
112 name = [% package_name %]
113 version = 0.01
114 author = Who AmI <me@whoami.com>
115 url = http://www.whereami.com/
116 sql_installer = OpenInteract2::SQLInstall::[% class_name %]
117 description = Description of package [% package_name %] goes here. Use can use '\' as a line continuation.
118  
119 # Dependencies: use multiple lines for multiple dependencies
120 module =
121  
122 # Other options: config_watcher, spops_file, action_file, message_file
123  
124 # Add template plugins here: key is name of plugin, value is class
125 [package template_plugin]
126  
127 # Register observers here: key is name of observer, value is class
128 [package observer]
129  
130  
131 SOMELONGSTRING
132 }
133  
134 1 ▶sub MANIFESTSKIP {
Subroutine MANIFESTSKIP: called CC=1 SCAR=0.0
Pod undocumented
135 1 return <<'SOMELONGSTRING';
136 \bCVS\b
137 ~$
138 ^oi2_manage\.log$
139 \.old$
140 \.bak$
141 \.backup$
142 ^tmp
143 ^_
144  
145 SOMELONGSTRING
146 }
147  
148 1 ▶sub SPOPSINI {
Subroutine SPOPSINI: called CC=1 SCAR=0.0
Pod undocumented
149 1 return <<'SOMELONGSTRING';
150 # spops.ini: define an object to be used by your package
151  
152 # Define the name by which OI2 uses to lookup this object class
153 #[[% package_name %]]
154  
155 # Class to be generated for object.
156 #class = OpenInteract2::[% class_name %]
157  
158 # Add parent classes for generated object
159 #isa =
160  
161 # field - List of fields/properties of this object. If this is a
162 # DBI-based object and you specify 'yes' for 'field_discover' below,
163 # you can leave this blank
164  
165 #field = id
166 #field = name
167 #field = type
168  
169 # Discover object fields at startup. (Recommended.)
170 #field_discover = yes
171  
172 # Name of primary key field
173 #id_field = [% package_name %]_id
174  
175 # If we should use auto-increment/sequence for IDs
176 #increment_field = yes
177  
178 # Name of sequence to use (Oracle, Postgres)
179 #sequence_name = [% package_name %]_seq
180  
181 # If set to 'yes' the object will be protected by security
182 #is_secure = yes
183  
184 # Fields for which we do not insert values. If you're using an
185 # auto-increment/sequence your ID field should be here.
186 #no_insert = [% package_name %]_id
187  
188 # Fields for which we should never update values.
189 #no_update = [% package_name %]_id
190  
191 # Values will not be inserted/updated if field is undefined.
192 #skip_undef =
193  
194 # Fields that have SQL defaults in the database
195 #sql_defaults =
196  
197 # Name of the table data are stored in.
198 #base_table = [% package_name %]
199  
200 # Additional names by which you can lookup this object class
201 #alias =
202  
203 # Field/method name used to generically generate an object's title
204 #name =
205  
206 # Name of this class of objects (e.g., 'News')
207 #object_name = [% class_name %]
208  
209 # Set to 'yes' for automatic full-text indexing.
210 #is_searchable = no
211  
212 # If searchable, list all fields to be indexed
213 #fulltext_field =
214  
215  
216 # Define a containing relationship. Key is class of object, value is
217 # the ID field in your object. So if your object contains a user ID
218 # field in 'user_id', you'd use 'OpenInteract2::User = user_id'; see
219 # SPOPS::Manual::Relationships' for details.
220  
221 #[[% package_name %] has_a]
222 #OpenInteract2::Theme = theme_id
223  
224 # Define a relationship between objects from this class and any number
225 # of other objects
226  
227 #[[% package_name %] links_to]
228 #OpenInteract2::Foo = foo_[% package_name %]_link
229  
230 # Security to apply to newly created objects from this class.
231 #[[% package_name %] creation_security]
232 #user = WRITE
233 #group = site_admin_group:WRITE
234 #world = READ
235  
236 # Specify actions to log
237 #[[% package_name %] track]
238 #create = no
239 #update = yes
240 #remove = yes
241  
242 # Every object can report its URL; using ACTION and TASK properly
243 # localizes the generated URL to your deployment context
244 #[[% package_name %] display]
245 #ACTION = [% package_name %]
246 #TASK = display
247  
248  
249 SOMELONGSTRING
250 }
251  
252 1 ▶sub ACTIONINI {
Subroutine ACTIONINI: called CC=1 SCAR=0.0
Pod undocumented
253 1 return <<'SOMELONGSTRING';
254 # This is a sample action.ini file. Its purpose is to define the
255 # actions that OpenInteract2 can take based on the URL requested or
256 # other means. The keys are commented below. (You can of course change
257 # anything you like. I've only used your package name as a base from
258 # which to start.)
259  
260 # '[% package_name %]' - Published name for this action; this is how
261 # other parts of OI2 find the action. (Will always be lower-case.)
262  
263 [[% package_name %]]
264  
265 # class - The class that will execute the action. Can be blank if it's
266 # a template-only action.
267  
268 class = OpenInteract2::Action::[% class_name %]
269  
270 # Other keys you might want to investigate -
271 # see OpenInteract2::Action for more:
272 #
273 # task_default: task to assign when none specified in the URL
274 # is_secure: whether Check security for this action or not (default: 'no')
275 # method: instead of calling arbitrary routines you can direct all requests to one
276 # action_type: base for action; OI2 comes with 'template_only' and 'lookup'
277  
278 SOMELONGSTRING
279 }
280  
281 1 ▶sub SQLINSTALLPM {
Subroutine SQLINSTALLPM: called CC=1 SCAR=0.0
Pod undocumented
282 1 return <<'SOMELONGSTRING';
283 package OpenInteract2::SQLInstall::[% class_name %];
284  
285 # Sample of SQL installation class. This uses your package name as the
286 # base and assumes you want to create a separate table for Oracle
287 # users and include a sequence for Oracle and PostgreSQL users.
288  
289 use strict;
290 use base qw( OpenInteract2::SQLInstall );
291  
292 my %FILES = (
293 pg => [ '[% package_name %].sql',
294 '[% package_name %]_sequence.sql' ],
295 default => [ '[% package_name %].sql' ],
296 );
297  
298 sub get_structure_set {
299 return '[% package_name %]';
300 }
301  
302 sub get_structure_file {
303 my ( $self, $set, $type ) = @_;
304 return $FILES{pg} if ( $type eq 'Pg' );
305 return $FILES{default};
306 }
307  
308 # Uncomment this if you're passing along initial data
309  
310 #sub get_data_file {
311 # return 'initial_data.dat';
312 #}
313  
314 # Uncomment this if you're using security
315  
316 #sub get_security_file {
317 # return 'install_security.dat';
318 #}
319  
320 1;
321  
322 SOMELONGSTRING
323 }
324  
325 1 ▶sub ACTIONPM {
Subroutine ACTIONPM: called CC=1 SCAR=0.0
Pod undocumented
326 1 return <<'SOMELONGSTRING';
327 package OpenInteract2::Action::[% class_name %];
328  
329 # This is a sample action. It exists only to provide a template for
330 # you and some notes on what these configuration variables mean.
331  
332 use strict;
333  
334 # All actions subclass OI2::Action or one of its subclasses
335  
336 use base qw( OpenInteract2::Action );
337  
338 # You almost always use these next three lines -- the first imports
339 # the logger, the second logging constants, the third the context
340  
341 use Log::Log4perl qw( get_logger );
342 use OpenInteract2::Constants qw( :log );
343 use OpenInteract2::Context qw( CTX );
344  
345 # Use whatever standard you like here -- it's always nice to let CVS
346 # deal with it :-)
347  
348 $OpenInteract2::Action::[% class_name %]::VERSION = sprintf("%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/);
349  
350 # Here's an example of the simplest response...
351  
352 sub hello {
353 my ( $self ) = @_;
354 return 'Hello world!';
355 }
356  
357  
358 # Here's a more complicated example -- this will just display all the
359 # content types in the system.
360  
361 sub list {
362 my ( $self ) = @_;
363  
364 # This will hold the data you're passing to your template
365  
366 my %params = ();
367  
368 # Retrieve the class corresponding to the 'content_type' SPOPS
369 # object...
370  
371 my $type_class = CTX->lookup_object( 'content_type' );
372 $params{content_types} = eval { $type_class->fetch_group() };
373  
374 # If we've encountered an error in the action, add the error message
375 # to it. The template has a component to find the errors encountered
376 # and display them
377  
378 if ( $@ ) {
379 $self->param_add( error_msg => "Failed to fetch content types: $@" );
380 }
381  
382 # The template also has a component to display a status
383 # message. (This is a silly status message, but it's just an
384 # example...)
385  
386 else {
387 my $num_types = scalar @{ $params{content_types} };
388 $self->param_add( status_msg => "Fetched $num_types types successfully" );
389 }
390  
391 # Every action should return content. It can do this by generating
392 # content itself or calling another action to do so. Here we're doing
393 # it ourselves.
394  
395 return $self->generate_content(
396 \%params, { name => '[% package_name %]::sample' } );
397 }
398  
399 1;
400  
401 SOMELONGSTRING
402 }
403  
404 1 ▶sub APPPM {
Subroutine APPPM: called CC=1 SCAR=0.0
Pod undocumented
405 1 return <<'SOMELONGSTRING';
406 package OpenInteract2::App::[% class_name %];
407  
408 use strict;
409 use base qw( Exporter OpenInteract2::App );
410 use OpenInteract2::Manage;
411  
412 $OpenInteract2::App::[% class_name %]::VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);
413 @OpenInteract2::App::[% class_name %]::EXPORT = qw( install );
414  
415 my $NAME = '[% package_name %]';
416  
417 sub new {
418 return OpenInteract2::App->new( $NAME );
419 }
420  
421 sub get_brick {
422 require OpenInteract2::Brick;
423 return OpenInteract2::Brick->new( $NAME );
424 }
425  
426 sub get_brick_name {
427 return $NAME;
428 }
429  
430 # Not a method, just an exported sub
431 sub install {
432 my ( $website_dir ) = @_;
433 my $manage = OpenInteract2::Manage->new( 'install_package' );
434 $manage->param( website_dir => $website_dir );
435 $manage->param( package_class => __PACKAGE__ );
436 return $manage->execute;
437 }
438  
439 OpenInteract2::App->register_factory_type( $NAME => __PACKAGE__ );
440  
441 1;
442  
443 __END__
« OpenInteract2/Brick/WebsiteConfig.pm ↑ Summary OpenInteract2/Setup/RequireSystemClasses.pm »